ADO.NET 实体框架的内部类

发布于 2024-08-26 14:10:09 字数 317 浏览 4 评论 0原文

我正在使用实体框架创建数据访问层,并且我希望所有类都是内部

我知道可以在设计器中为每个类手动分配它。

更新 我发现我最初的陈述

但看起来它还需要为每个类中的每个属性设置内部修饰符!我有大约 30 多个实体,这将是一项艰巨的工作。

是不正确的。我错过了当我在实体类型上设置访问权限时,我还需要在实体集上设置适当的访问权限。

您知道如何为整个模型设置“默认访问权限”吗?

I'm using Entity Framework for creation of my Data Access Layer and I want for all of my classes to be internal.

I know it is possible to manually assign it in the designer for each class.

UPDATE
I found that my initial statement

But looks like it also requires to set internal modifier for each single property in every class! I have about 30+ entities and it will be a huge work to do.

was incorrect. I was missing that when I set access on Entity Type I need to set an appropriate access on Entity Set as well.

Do you know any ideas how to set a 'default access' for the entire model?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

长不大的小祸害 2024-09-02 14:10:10

您到底想实现什么目标?如果模型中的每个类都被声明为内部的,并且它的所有属性都被声明为内部的,那么您的模型就会毫无用处。有时需要某些东西来访问它并使用它......

您是否试图阻止模型的特定使用?有更好的方法可以做到这一点。

更新:
看起来 VS2010 将允许通过 T4 模板创建内部 ObjectContext。看看这里: http ://blogs.msdn.com/efdesign/archive/2009/01/22/customizing-entity-classes-with-t4.aspx

What are you trying to achieve exactly? If every class in your model was declared internal and all of it's properties were declared internal, it would make your model useless. Something will need to access it and work with it sometime...

Are you trying to prevent a specific usage of the model ? There are better ways to do this.

UPDATE:
It looks like VS2010 will allow an internal ObjectContext through T4 templating. Have a look here: http://blogs.msdn.com/efdesign/archive/2009/01/22/customizing-entity-classes-with-t4.aspx

素手挽清风 2024-09-02 14:10:09

实际上,如果您的类是内部类,则属性是否是公共的并不重要 - 类本身在项目外部不可见,因此永远无法访问这些属性(除非通过反射)

Actually if your class is internal, it doesn't matter if the properties are public - the class itself isn't visible outside your project, so the properties can never be accessed (unless through reflection)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文