Reputation: 5784
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:
at:
db.Regions.Add(newRegion);
I have a 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; }
}
}
Upvotes: 0
Views: 32
Reputation: 62311
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();
}
Upvotes: 2