Note that there are some explanatory texts on larger screens.

plurals
  1. POIs there a way to automatically load navigational property using the .NET Entity Framework?
    primarykey
    data
    text
    <p>Stepping away more and more from writing SQL for my applications, I decided to give the Entity Framework a try. However, I've run into something I believe is causing me to write more code than I think is strictly necessary.</p> <p>When I accessed some navigational properties, I discovered that all many-to-one relations (simple references) were null and all one-to-many and many-to-many relations (EntityCollections) were empty.</p> <p>For example: I have a User with a reference to a Group. When I have retieved a User, by using a simple select-by-id, the Group property is null. If I want to access the Group I have to manually load it (using User.GroupReference.Load()). So I added a GetGroup() method in User which checks whether the Group is loaded already and, if not, does so and then returns the Group.</p> <p>Now this will result in a lot of highly similar methods for all navigational properties. And it all results in the navigational properties not being used, only my custom-made Get"PropertyName"() method's are now being used.</p> <p>I don't want to expand my queries (linq to entities) to immediately load all these properties, because it's not always known at first what is needed. And besides, it would cause a lot of queries to have to be made.</p> <p>Is there a way to configure the Entity Framework to load these objects when they happen to not be present? So when I access User.Group and the group is not loaded yet, it is loaded automatically? Or am I stuck using my own Get"PropertyName"() method's as long as I'm trying to load objects only on demand (or "just-in-time")?</p> <p>Some extra info: I'm using VS2008 SP1 with .NET 3.5 SP1. The Entity Framework I'm using is the one that got shipped with it.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload