ADO.NET 实体框架的内部类
我正在使用实体框架创建数据访问层,并且我希望所有类都是内部
。
我知道可以在设计器中为每个类手动分配它。
更新 我发现我最初的陈述
但看起来它还需要为每个类中的每个属性设置内部修饰符!我有大约 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您到底想实现什么目标?如果模型中的每个类都被声明为内部的,并且它的所有属性都被声明为内部的,那么您的模型就会毫无用处。有时需要某些东西来访问它并使用它......
您是否试图阻止模型的特定使用?有更好的方法可以做到这一点。
更新:
看起来 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
实际上,如果您的类是内部类,则属性是否是公共的并不重要 - 类本身在项目外部不可见,因此永远无法访问这些属性(除非通过反射)
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)