Johnny Oshika
Johnny Oshika

Reputation: 57502

Entity Framework 6: Lazy loading doesn't work when classes are internal

I'm using Entity Framework 6 and I have lazy loading enabled:

enter image description here

When I set my entity class Access to 'public, lazy loading works fine:

enter image description here In the example above, I'm able to navigate from Address to City.

However, if I change the entity class Access to 'internal', then lazy loading stops working and I can no longer navigate from Address to City if I don't eager load City:

enter image description here

enter image description here

Why does lazy loading stop working for internal classes? Is there a way around this?

Upvotes: 2

Views: 1249

Answers (1)

ken2k
ken2k

Reputation: 48975

The entity must be public, it's a requirement for Entity Framework to be able to inherit from it and create a proxy at runtime (that adds all the EF internal stuff in the overridden virtual navigation properties).

See Requirements for Creating POCO Proxies on MSDN.

Upvotes: 7

Related Questions