为什么使用实体框架时,我看不到属性本地? [英] Why can I not see the property Local when using Entity Framework?

查看:92
本文介绍了为什么使用实体框架时,我看不到属性本地?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我失去了一些东西完全明显,但为什么我不能看到属性本地与EF环境中工作时?典型的例子在线如下所示:

I know I am missing something completely obvious, but why can't I see the property Local when working with an EF context? The typical example online looks like the following:

context.Parents.Local

但我无法看到本地属性。现在,从我的理解,当地是DbSet类的成员,我不认为我在我的应用程序与DbSet工作。我所知道的是我已经添加使用System.Data.Entity的到的EntityFramework,有引用和其他一切我熟悉做的工作就好了。除了本地是不存在的,而且我真的需要为我的 DataGridView的

But I am unable to see the Local property. 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. 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. Except Local isn't there, and I really do need some sorting capability for my DataGridView.

帮助!

推荐答案

如果你看看你自动生成的代码的上下文类,它与的DbContext或ObjectContext的继承?

If you look at your auto-generated code for the context class, does it inherit from DbContext or ObjectContext?

如果是从ObjectContext的继承,也有你需要采取一些步骤。

If it is inheriting from ObjectContext, there are a few more steps you need to take.


  • 在模型设计图面上,右键单击 - >添加代码生成项

  • 选择代码从左边

  • 选择菜单ADO.NET DbContextGenerator

  • 名称(如项目一样的模型:为MyModel )

  • 单击添加

  • On the model design surface, Right Click->Add Code Generation Item
  • Select 'Code' from the menu on the left
  • Select 'ADO.NET DbContextGenerator'
  • Name the item the same as your model (ex: 'MyModel')
  • Click Add

两个* .TT文件将被添加到您的项目称为东西像MyModel.tt和MyModel.Context.tt。

Two *.tt files will be added to your project called something like MyModel.tt and MyModel.Context.tt.

重新编译后,查看了您的上下文自动生成的代码再次,现在应该从继承的DbContext。你的父母反对现在将类型DbSet而不是对象集,现在您就可以使用本地属性。

After a recompile, look at your auto-generated code for the context again and it should now inherit from DbContext. Your Parents object will now be of type DbSet instead of ObjectSet and you will now be able to use the Local property.

这篇关于为什么使用实体框架时,我看不到属性本地?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆