6

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.

Minnie
  • 257
  • 3
  • 16

1 Answers1

5

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.

Julie Lerman
  • 4,602
  • 2
  • 22
  • 21
  • 1
    Thank you for your answer. Looks like nobody had similar experience. I have tried your suggestion, it did not make any difference. – Minnie Nov 27 '11 at 19:24
  • Looks like it doesn't work... Maybe the instances of the entities are not created by the DbContext derived class but inside the core execution engine of EF... – Nock Jan 15 '13 at 12:35