AsNoTracking() Method Is Missing From Context in Entity Framework

c# entity-framework winforms


I need to load an entire table into memory using Entity Framework 4.0. I have spent the last 2 hours reading about the AsNoTracking() method that should do the trick but, I cannot figure out why the method is not available on my dataContext. Based on everything I have read, I should merely need a reference to System.Data.Entity. Then, I should be able to use the AsNoTracking() method when loading my objects. Am I missing something simple here? Is this method not available in EF 4.0? Nevertheless, below is one of the queries from my code.

// Working Query
var items = dbContext.Items.ToList()

// Does NOT Work (Compiler does not recognize AsNoTrackingMethod() )
var items = dbContext.Items.AsNoTracking().ToList()
2/20/2014 8:12:17 PM

Accepted Answer

AsNoTracking() is an extension method, which was added in Entity Framework 4.1 (as ability to return non-cached results). That's why you don't have it in Entity Framework 4.0. I suggest you to upgrade version of Entity Framework, if it is possible (BTW current version is 6.0).

2/20/2014 8:49:36 PM

Popular Answer

AsNoTracking() is an extension method in the DbExtensions (EF5)/QueryableExtensions (EF6) class, which is part of the System.Data.Entity namespace. It is not missing from Entity Framework 4.1+. You simply need to remember to add a using directive for that namespace.

using System.Data.Entity;

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow