Entity Framework Code First internal class - is it possible?

北战南征 提交于 2019-12-10 17:33:57

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/8250339/entity-framework-code-first-internal-class-is-it-possible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!