Entity Framework Code First internal class - is it

2019-06-23 17:53发布

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条回答
SAY GOODBYE
2楼-- · 2019-06-23 18:30

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.

查看更多
登录 后发表回答