The ArgumentNullException certainly wasn't intentional, but this has never worked the way you think it does.
EntityQuery<Organisation> query510 = EntityManager.Parties.OfType<Organisation>().ToQuery<Organisation>();
|
The ToQuery<Organisation>() clause actually causes two things to occur -
1) First and most importantly, and probably not your intention, is it causes the query, EntityManager.Parties.OfType<Organisation>(), to be enumerated. This results in the query being sent to the database at this time. You can see why the query is enumerated in looking at the method signature:
public static EntityQuery<T> ToQuery<T>(this IEnumerable<T> entities) where T : Entity
|
2) Once the entities are returned, a new (possibly quite large) query is built based on the keys returned. So you end up with a query which looks something like this - ... Where ... and (Id=1 or Id=2 or Id=3 ...). You can see the query built by doing a query510.ToString() call. You can also use a profiler to see what's sent to the database when query510.ToList() is executed. It's likely not pretty.
So, I'm assuming what you really want is to build a query which filters for a sub-type, and control how the query is executed either through enumeration or explicit execution. The easiest way to do this is to leave out the ToQuery() -
EntityQuery<Organisation> query510 = EntityManager.Parties.OfType<Organisation>();
var results = query510.ToList();
|
For the record, there are other ways to build up a query for a sub-type, here are a few -
var query2 = EntityManager.Parties.Where(o=> o is Organisation);
var query3 = EntityManager.GetQuery<Organisation>();
|
|