New Posts New Posts RSS Feed: EntityQueryBuilder.BuildQuery from array of EntityKeys only creates from first EntityKey EntityType
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

EntityQueryBuilder.BuildQuery from array of EntityKeys only creates from first EntityKey EntityType

 Post Reply Post Reply
Author
pk55 View Drop Down
Senior Member
Senior Member


Joined: 22-Jul-2009
Location: CA
Posts: 105
Post Options Post Options   Quote pk55 Quote  Post ReplyReply Direct Link To This Post Topic: EntityQueryBuilder.BuildQuery from array of EntityKeys only creates from first EntityKey EntityType
    Posted: 30-Dec-2010 at 1:11pm
I was trying to use the EntityQueryBuilder.BuildQuery method to load a bunch of different entities by passing an array of EntityKey.  Each key in the array is a valid entitytype/key values[] combination but the resulting query only uses the EntityType of the first EntityKey and uses the values from each entity key as if they belonged to the first entity type.
 
Is this expected behavior?  Does this method only work for a single entity type?
Back to Top
pk55 View Drop Down
Senior Member
Senior Member


Joined: 22-Jul-2009
Location: CA
Posts: 105
Post Options Post Options   Quote pk55 Quote  Post ReplyReply Direct Link To This Post Posted: 30-Dec-2010 at 3:37pm

This behavior is really misleading when no exception is thrown but the entities are loaded that weren't asked for.

In my case, the three entities I have EntityKeys for (one key per entity in this case) happened to use a single int key so the query could be built (here's what the keys contained):
EntityKeys[0].EntityType = User; EntityKeys[0].Values[0] = 1;
EntityKeys[1].EntityType = Status; EntityKeys[1].Values[0] = 3;
EntityKeys[2].EntityType = Group; EntityKeys[2].Values[0] = 4;
The query built was basically:
var query = em.User.Where (x => (((x.UserID == 1) OrElse (x.UserID == 3)) OrElse (x.UserID ==4)));
when it should have created three queries:
var query1 = em.User.Where (x => x.UserID == 1);
var query2 = em.Status.Where (x => x.StatusID ==3);
var query3 = em.Group.Where (x => x.GroupID ==4);
 
I assume there would be an exception thrown if I passed multiple entity keys for different entities with different structures or different number of keys.  Either DevForce should throw an error if it gets mixed EntityTypes or it should only build the where clause based on keys matching the first entity type OR (and this would be my choice) it should do what I had to do:
 
I'm splitting up the EntityKeys into type-specific arrays of EntityKeys in a CoRoutine Parallel Async task and then building and executing the query for each specific type for all matching keys of that type.
 
I assume this is also an issue if you use an EntityKeyList.ToQuery method.  Haven't tried that but it also looks like it expects a single entity type.
 
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 30-Dec-2010 at 3:37pm
Hi pk55,
 
You can only build an EntityQuery<T>. Because of that, you shouldn't have an array with keys from multiple entities.
 
While the above described is the expected behavior (T will be the first entity type found in the array), I think it's not quite appropriate. I'm adding a feature request to check for entity type consistency in the EntityKey array.
 
Silvio.
Back to Top
pk55 View Drop Down
Senior Member
Senior Member


Joined: 22-Jul-2009
Location: CA
Posts: 105
Post Options Post Options   Quote pk55 Quote  Post ReplyReply Direct Link To This Post Posted: 30-Dec-2010 at 4:13pm
I suppose that's your only choice since it's just building a query; not executing it at the same time.  I'll just use what I'm doing now.  Thanks.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down