为什么使用实体框架时,我看不到属性本地?

编程入门 行业动态 更新时间:2024-10-26 10:38:51
本文介绍了为什么使用实体框架时,我看不到属性本地?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我知道我失去了一些东西完全明显,但为什么我不能看到属性本地与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.

更多推荐

为什么使用实体框架时,我看不到属性本地?

本文发布于:2023-11-27 20:34:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1639506.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:我看   实体   框架   属性

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!