Skip to content Skip to sidebar Skip to footer

Can I Easily Evaluate Many Iqueryables In A Single Database Call Using Entity Framework?

Suppose I have a collection (of arbitrary size) of IQueryable (all for the same MyEntity type). Each individual query has successfully been dynamically built to enc

Solution 1:

No. EF deosn't have query batching (future queries). One queryable is one database roundtrip. As a workaround you can try to play with it and for example use:

string sql = ((ObjectQuery<Widget>)context.Widgets.Where(...)).ToTraceString();

to get SQL of the query and build your own custom command from all SQLs to be executed. After that you can use similar approach as with stored procedures to translate results.

Unless you really need to have each query executed separately you can also union them to single query:

context.Widgets.Where(...).Union(context.Widgets.Where(...));

This will result in UNION. If you need just UNION ALL you can use Concat method instead.

Solution 2:

It might be late answer, hopefully it would help some one else with the same issue.

There is Entity Framework Extended Library on NuGet which provides the future queries feature (among others). I played a bit with it and it looks promising.

You can find more information here.

Post a Comment for "Can I Easily Evaluate Many Iqueryables In A Single Database Call Using Entity Framework?"