Print Page | Close Window

Joining EntityRelations from two seperate queries

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2009
Forum Discription: For .NET 3.5
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3613
Printed Date: 17-Oct-2019 at 5:38am


Topic: Joining EntityRelations from two seperate queries
Posted By: matt.cavagnaro
Subject: Joining EntityRelations from two seperate queries
Date Posted: 07-Sep-2012 at 12:20pm
Hello.

Say there is a Team object for a given type of sport. And a Player object which has a FK to Team.

I'm querying for all the Team objects, then later, after the user selects a certain option I'm querying for all of the Player objects seperately.

Normally, I think the easiest way to go about it would be to Query for Teams with an .Include(i => i.Players) option. However, in our case this leads to time outs for our users, we have hundreds of Team objects and each Team may more than 1000 Players with their own navigation properties that need Includes. We have a custom class that divides larger queries into several smaller chunks, but this does not chunk Includes.

I guess I want to know if it's possible to Query for Team objects, then later, on demand, be able to query for the Player objects associated with any given team and have the Team's Players collection not be a PendingEntityList.

I've tried two separate queries from the same EntityManager, so by my understanding they should definitly be in the same cache, but after querying for Players for a given team, the entire collection of Team.Players lazy loads when I try to access it.

Also, if, after querying for Players with an Include on Team, I do

IEnumerable<Team> teams = Players.Select(i => i.Teams).Distinct();

The Team objects in teams all say that .Players is a PendingEntityList.

Hopefully this is all clear, if clarification is needed let me know and I'll try my best to reword things. Been reading about this all morning and haven't really gotten closer to a solution.



Replies:
Posted By: kimj
Date Posted: 10-Sep-2012 at 12:42pm
Hi Matt,
 
It is possible to query for Teams, and then later query for Players on one of these teams and not have a PendingEntityList involved.  DevForce can't know with any certainty that all the players for a team are already in cache, and so takes the safe approach of issuing a query to ensure everything is loaded.  If you know that all of a team's players are in cache you can turn off this default behavior by setting the EntityReferenceStrategy for the relation, like this:
 
  Team.PropertyMetadata.Players.ReferenceStrategy = EntityReferenceStrategy.NoLoad
 
The "NoLoad" strategy tells DevForce to look only in cache for the related items. 
 
Here's some more information on the reference strategy - http://drc.ideablade.com/xwiki/bin/view/Documentation/navigation-properties-data-retrieval - http://drc.ideablade.com/xwiki/bin/view/Documentation/navigation-properties-data-retrieval .



Print Page | Close Window