Entity Framework span and eager fetch
Some minutes ago I posted about the Entity Framework and fetching strategy. After a little search in the documentation, I finally found how to prefetch using a concept called * span *. Here is a LINQ query that load a department eagerly fetching the courses collection
|
|
Using the span is simple as calling method * Include() *in the Department property of the EF context. This solves in part the problem because I still do not like that, if you forget to eager fetch or manually lazy fetch calling * EntityRef.Load() *, you can access the collection and find it empty. I think that raise an exception or some warning should be done, to warn the programmer that he is accessing a collection that is not in sync with data in the database. Accessing an unfetched collection can mislead the programmer that there are no related object in database.
Alk.