Description
While users can execute multiple updates in a single ADO batch, no such feature currently exists for reading - each query is executed separately. For example, if a single web request requires multiple queries to fulfill (fairly typical case IMHO), then that many database roundtrips have to occur.
Reducing roundtrips can bring a very significant performance boost, so some sort of API which allows a user to defined multiple queries and have them executed together could be useful.
Note that there is a trade-off here: batching typically implies buffering the earlier query results, so the memory overhead is (potentially much) larger than executing different queries and streaming their results; if the results are small, batching makes sense, but if they're huge, multiple queries may make more sense.
The buffering overhead could mitigated by MARS, where supported. In other words, the user-defined "read batch" could actually execute multiple MARS queries (in one roundtrip, if supported), and allow the user to stream the results. Ideally, the user-facing "batching" API shouldn't expose this.
Note: this issue isn't about using batching in internally-generated queries (that's what #10878 is about).
Activity
smitpatel commentedon Feb 6, 2018
Related #8127
popcatalin81 commentedon Feb 8, 2018
This feature would be very useful to have for the apps I'm currently working on (online-offline sync by reading delta changes from a set of tables)
NinoFloris commentedon Mar 16, 2018
Was just looking for this!
Our scenario absolutely demands collection based retrieval instead of joins as our joined tables have low cardinality and a lot of columns/data. However currently EF doesn't provide any other option than trading transfer time for roundtrips.
https://github.com/zzzprojects/EntityFramework-Plus/tree/master/src/shared/Z.EF.Plus.QueryFuture.Shared brings this functionality but at an extremely high cost, an 80ms request becomes 100ms so there is no win in small result sets at all.
Most likely this is because of all the ad-hoc reflection and reparsing of queries, it works but it's far from optimal.
I would love a read batching api.
AndriySvyryd commentedon Jan 30, 2020
Related: #18990
roji commentedon Aug 10, 2020
This seems to be a feature of EF Plus: https://entityframework-plus.net/query-future
roji commentedon Mar 3, 2021
Possibly consider batching updates as well.
AndriySvyryd commentedon Mar 3, 2021
Both bulk and regular ones.
Also consider
FromSqlandFind[-]Expose batching read API to users[/-][+]Execute multiple LINQ queries in a single round-trip (aka Expose batching read API to users)[/+]ziaulhasanhamim commentedon Sep 9, 2022
Will this feature ever arrive?
26 remaining items
ExecuteAssert#33329 as a duplicate of this issueAdd query batching: execute multiple LINQ queries in a single round-trip
Support ExecuteDelete/ExecuteUpdate in query batches
Add tests for remaining query batching error paths
Add query batching: execute multiple LINQ queries in a single round-trip
Support ExecuteDelete/ExecuteUpdate in query batches
Add tests for remaining query batching error paths
Add query batching: execute multiple LINQ queries in a single round-trip
Support ExecuteDelete/ExecuteUpdate in query batches
Add tests for remaining query batching error paths