开发者

How to query entities from unrelated tables in one batch

I would like to query to different Tables, say apples and cars, which have no relationship so that active record goes only once to the database.

Example in pseudocode:

var q1 = new Query("select * form apple");
var q2 = new Query("select * from car");

var batchQuery = new BatchQuery(q1,q2);
var result = BatchQuery.Execute();  //only one trip to the database

var apples = result[0] as IEnumerable<Apple>;
var cars = result[1] as IEnumerable<Car>;

I have tried ActiveRecordMultiQuer开发者_运维百科y, but there all Queries need to query the same table.


I don't believe there is a way to do this.

It seems like you might be going a bit overboard with optimization here: does it really make a noticeable difference to your application to make 2 separate queries? I think your time might be better spent looking for N+1 select queries elsewhere in your application instead.

If the cost of one extra query is in fact significant then you probably have an issue with the database server or the connection to it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜