New Posts New Posts RSS Feed: Deferred loading of empty relations
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Deferred loading of empty relations

 Post Reply Post Reply
Author
allo View Drop Down
Newbie
Newbie
Avatar

Joined: 27-Oct-2008
Location: Toronto, ON
Posts: 7
Post Options Post Options   Quote allo Quote  Post ReplyReply Direct Link To This Post Topic: Deferred loading of empty relations
    Posted: 28-Oct-2008 at 12:19pm
Hi,
 
We're currently evaluating DevForce EF, and have come across some unexpected behavior.
There's a possibility that this behavior is as-designed, but it would seem rather irrational, so here goes :
 
We have a self-referencing Category table with internal hierarchical relationships.
Certainly, the business class Category has a collection property called Children to represent the relationship.
To get the entire hierarchy at once and to prevent any subsequent lazy-loading round-trips, we do something like this:
 
var qry = from c in mgr.Categories.Include(Category.PathFor(c => c.Children))select c;
 
Both the SQL Profiler and DebugLog.xml show that the original request indeed contains the instructions to include the span, and the collections certainly get populated correctly.
The awkward thing is this: when we subsequently access the Children collection on those entities that have no such children, an extra lazy-load request is made to the server.
It almost looks like the framework is for some reason unable to distinguish between a never-loaded collection and an emtpy one. Another possibility could be in the principle that the framework simply attempts to see if there's any children now as opposed to originally, which would itself present an inconsistency since in that case it would also have to go and see if there are new/deleted children in those entities that already had children, - yet this is not happening.
 
Advance thanks for any helpful information!
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 28-Oct-2008 at 7:31pm

This behavior is not by design, and we've opened a bug report to fix it.  You're correct that the framework is not distinguishing between a never-loaded collection and an empty one.  The good news, such as it is, is that the problem does not occur with scalar navigation properties, so going in the parent direction, e.g., aChild.ParentCategory, does not result in an unnecessary call to the server.

For right now, as a workaround you can set the ReferenceStrategy on the relation role in question, forcing it to not attempt to lazily load.  The strategy is set on a role (or roles) in an EntityRelation, for example:
 
   EntityRelations.FK_Categories_Categories.Role2.ReferenceStrategy = EntityReferenceStrategy.NoLoad;
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 04-Dec-2008 at 10:49am
This problem has been fixed, and will be available in release 4.2.2.x, due December 10.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down