实体框架代码优先内部类 - 可能吗?
是否可以使用内部访问来声明 Code First 数据类,如下所示:
internal class Person
{
public int Id { get; set; }
public string Name { get; set; }
}
我要求类及其属性在程序集外部不可见。
Is it possible to have Code First data classes declared with internal access as shown:
internal class Person
{
public int Id { get; set; }
public string Name { get; set; }
}
I have a requirement that classes and its properties should not be visible outside of the assembly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只要将您的类公开给 EF 的 DbContext 派生类位于同一个程序集中,您就应该能够这样做。我碰巧不会以这种方式设计我的应用程序,因为我更喜欢更多的分离。但是上下文应该能够构建模型,并且如果它们位于同一个程序集中,它应该能够与类进行交互(例如执行查询、保存更改等),因为它将有权访问内部类。即使我们在 Code First 书中尝试并写了各种奇怪的事情,我也从未碰巧尝试过这种特殊的场景。
As long as your DbContext derived class that exposes your class to EF is in the same assembly, you should be able to. I don't happen to design my apps that way as I prefer more separation. But the context should be able to build the model and it should be able to interact with the classes (e.g. execute queries, save changes etc) if they are in the same assembly since it will have access to the internal class. Even with the various odd things we tried and wrote about in the Code First book, I never happened to try this particular scenario.