[英]Why can I not see the property Local when using Entity Framework?
I know I am missing something completely obvious, but why can't I see the property Local
when working with an EF context? 我知道我遗漏了一些显而易见的东西,但是为什么在使用EF上下文时看不到属性
Local
? The typical example online looks like the following: 网上的典型示例如下所示:
context.Parents.Local
But I am unable to see the Local
property. 但是我看不到
Local
属性。 Now from what I understand, Local is a member of the DbSet class, and I don't think I'm working with a DbSet in my application. 现在,据我了解,Local是DbSet类的成员,并且我认为我没有在应用程序中使用DbSet。 What I do know is I've added a reference to the EntityFramework, have
using System.Data.Entity
and everything else I'm familiar with doing is working just fine. 我所知道的是,我已经添加了对EntityFramework的引用,
using System.Data.Entity
而我所熟悉的其他一切工作都很好。 Except Local
isn't there, and I really do need some sorting capability for my DataGridView
. 除了
Local
不存在之外,我确实确实需要对DataGridView
排序的功能。
Help! 救命!
DbContext
, DbSet
etc. are part Entity Framework 4.1/4.2 which is shipped, among others, as the EntityFramework NuGet package. DbContext
, DbSet
等是Entity Framework 4.1 / 4.2的一部分,它作为EntityFramework NuGet软件包提供。 With just the .NET Framework you only have what is now called "Core EF Runtime" according to this : 只需在.NET Framework你只有现在所谓的“核心EF运行”,按照此 :
In short, you need to install EF 4.1/4.2. 简而言之,您需要安装EF 4.1 / 4.2。
If you look at your auto-generated code for the context class, does it inherit from DbContext or ObjectContext? 如果查看上下文类的自动生成的代码,它是否继承自DbContext或ObjectContext?
If it is inheriting from ObjectContext, there are a few more steps you need to take. 如果它是从ObjectContext继承的,则还需要执行几个步骤。
Two *.tt files will be added to your project called something like MyModel.tt and MyModel.Context.tt. 两个* .tt文件将被添加到您的项目中,名为MyModel.tt和MyModel.Context.tt。
After a recompile, look at your auto-generated code for the context again and it should now inherit from DbContext. 重新编译后,再次查看该上下文的自动生成的代码,它现在应该继承自DbContext。 Your Parents object will now be of type DbSet instead of ObjectSet and you will now be able to use the Local property.
现在,您的Parents对象将是DbSet类型而不是ObjectSet类型,并且您现在将能够使用Local属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.