0

I'm using Entity Framework and database first. Is it possible to generate entities that exposes readonly properties for navigation properties? If that is possible is it still possible to use eager loading?

Erik Z
  • 4,660
  • 6
  • 47
  • 74
  • take a look at this http://stackoverflow.com/questions/12798502/entity-framework-entity-read-only-property-mapped-to-a-column-of-related-table – Ehsan Feb 14 '14 at 13:16

1 Answers1

0

Do you mean something like this?

public class MyEntity
{
    public virtual OtherEntity Other { get; protected set; }
}

While technically not readonly, your code is unable to set this property. You can still eager load it though because the accessor is public -- only the mutator is protected, which means you can't access it unless you are a member in the class or overriding the class.

Update:

EF does not yet support ReadOnlyCollection properties, but there may be a workaround here.

Community
  • 1
  • 1
danludwig
  • 46,965
  • 25
  • 159
  • 237