[英]AsNoTracking() Method Is Missing From Context in Entity Framework
I need to load an entire table into memory using Entity Framework 4.0. 我需要使用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.
我花了最后2个小时阅读AsNoTracking()方法应该做的技巧但是,我无法弄清楚为什么这个方法在我的dataContext上不可用。 Based on everything I have read, I should merely need a reference to System.Data.Entity.
根据我读过的所有内容,我只需要对System.Data.Entity的引用。 Then, I should be able to use the AsNoTracking() method when loading my objects.
然后,我应该能够在加载我的对象时使用AsNoTracking()方法。 Am I missing something simple here?
我错过了一些简单的东西吗? Is this method not available in EF 4.0?
这种方法在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()
AsNoTracking() is an extension method in the DbExtensions ( EF5 )/QueryableExtensions ( EF6 ) class, which is part of the System.Data.Entity namespace. AsNoTracking()是在DbExtensions(扩展方法EF5 )/ QueryableExtensions( EF6 )类,它是System.Data.Entity的命名空间的一部分。 It is not missing from Entity Framework 4.1+.
实体框架4.1+并未遗漏任何内容。 You simply need to remember to add a using directive for that namespace.
您只需要记住为该命名空间添加using指令。
using System.Data.Entity;
AsNoTracking()
is an extension method, which was added in Entity Framework 4.1 (as ability to return non-cached results). AsNoTracking()
是一种扩展方法,已添加到Entity Framework 4.1中(作为返回非缓存结果的能力)。 That's why you don't have it in Entity Framework 4.0. 这就是为什么你没有在Entity Framework 4.0中拥有它。 I suggest you to upgrade version of Entity Framework, if it is possible (BTW current version is 6.0).
我建议您升级Entity Framework的版本,如果可能的话(BTW当前版本是6.0)。
如果从.NET Core使用EF使用指令:
using Microsoft.EntityFrameworkCore;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.