I'm in weired situation. I read about context.Configuration.AutoDetectChangesEnabled = false; and decide to use it.
But I cant found it. the code is
using (DefaultCS db = new DefaultCS())
{
db.Configuration.AutoDetectChangesEnabled = false;
order.OrderTables = TableNo;
order.OrderMenus = oMenu;
db.Orders.AddObject(order);
db.SaveChanges();
}
I got error at db.Configuration which is ROS.DefaultCS does not contain a definition for 'Configuration' and no extension method 'Configuration' accepting a first argument of type 'ROS.DefaultCS' could be found (are you missing a using directive or an assembly reference?)
what I'm missing? I'm using EF4.
Here is the answer: in Entity Framework 4 we should use db.Orders.MergeOption = MergeOption.NoTracking; instead of db.Configuration.AutoDetectChangesEnabled = false; which is only applicable in Entity Framework 5.
Code for EF4 and EF5
In EF4
db.Orders.MergeOption = MergeOption.NoTracking;
In EF5
db.Configuration.AutoDetectChangesEnabled = false;
The downgrade for EF4 is to set it for each Entity.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With