Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EF4: AutoDetectChangesEnabled not found

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.

like image 764
صفي Avatar asked Sep 01 '26 08:09

صفي


1 Answers

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.

like image 150
صفي Avatar answered Sep 05 '26 15:09

صفي