I realized that you are using MVC 4 with VS2012, and the default version of Entity Framework is 5.
Now how are you deletefrom EF4.
Here is the correct way deletewithEF5
using (var db= new AppContext(ConnectionStr))
{
try
{
con.Configuration.AutoDetectChangesEnabled = false;
var o = new Store { Id = 1 };
db.Stores.Attach(o);
db.Stores.Remove(o);
db.SaveChanges();
}
catch (Exception ex)
{
throw new Exception(ex.InnerException.Message);
}
finally
{
con.Configuration.AutoDetectChangesEnabled = true;
}
}
source
share