New Posts New Posts RSS Feed: Joining EntityRelations from two seperate queries
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Joining EntityRelations from two seperate queries

 Post Reply Post Reply
Author
matt.cavagnaro View Drop Down
Newbie
Newbie


Joined: 09-Aug-2012
Posts: 7
Post Options Post Options   Quote matt.cavagnaro Quote  Post ReplyReply Direct Link To This Post Topic: Joining EntityRelations from two seperate queries
    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.
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: 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. 
 
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down