简体   繁体   English

具有ADO.NET实体框架的内部类

[英]Internal classes with ADO.NET Entity Framework

I'm using Entity Framework for creation of my Data Access Layer and I want for all of my classes to be internal . 我正在使用Entity Framework来创建我的数据访问层,我希望我的所有类都是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. 我有大约30多个实体,这将是一项巨大的工作。

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. 我错过了当我在Entity Type上设置访问权限时,我也需要在Entity SetEntity Set适当的访问权限。

Do you know any ideas how to set a 'default access' for the entire model? 您是否知道如何为整个模型设置“默认访问权限”?

实际上,如果你的类是内部的,那么属性是否公开并不重要 - 类本身在项目之外是不可见的,因此永远不能访问属性(除非通过反射)

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. 更新:看起来VS2010将通过T4模板允许内部ObjectContext。 Have a look here: http://blogs.msdn.com/efdesign/archive/2009/01/22/customizing-entity-classes-with-t4.aspx 看看这里: http//blogs.msdn.com/efdesign/archive/2009/01/22/customizing-entity-classes-with-t4.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM