Suffii Suffii - 2 months ago 10
ASP.NET (C#) Question

Having Issue on Adding Data To entity Framework Table

Can you please let me know why I am not able to add data to

Region
table here

protected void Button4_Click(object sender, EventArgs e)
{
Region newRegion = new Region()
{
RegionID = 5000,
RegionDescription = TextBox1.Text

};

db.Regions.Add(newRegion);
db.SaveChanges();

}


I am getting this error:

enter image description here

at:

db.Regions.Add(newRegion);


I have Region class as:

namespace EFDataStore
{
using System;
using System.Collections.Generic;

public partial class Region
{
public int RegionID { get; set; }
public string RegionDescription { get; set; }
}
}

Win Win
Answer

It seems that you have namespace conflict. You will need full namespace for Region class.

protected void Button4_Click(object sender, EventArgs e)
{
    var newRegion = new EFDataStore.Region() <==== Need full namespace.
    {
        RegionID = 5000,
        RegionDescription = TextBox1.Text

    };

    db.Regions.Add(newRegion);
    db.SaveChanges();

}
Comments