Skip to content

Execute multiple LINQ queries in a single round-trip (aka Expose batching read API to users) #10879

Description

@roji

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

  1. smitpatel commented on Feb 6, 2018

    @smitpatel
    Contributor

    Related #8127

  2. added this to the Backlog milestone on Feb 7, 2018
  3. popcatalin81 commented on Feb 8, 2018

    @popcatalin81

    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)

  4. NinoFloris commented on Mar 16, 2018

    @NinoFloris

    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.

  5. AndriySvyryd commented on Jan 30, 2020

    @AndriySvyryd
    Member

    Related: #18990

  6. roji commented on Aug 10, 2020

    @roji
    MemberAuthor
  7. roji commented on Mar 3, 2021

    @roji
    MemberAuthor

    Possibly consider batching updates as well.

  8. AndriySvyryd commented on Mar 3, 2021

    @AndriySvyryd
    Member

    Possibly consider batching updates as well.

    Both bulk and regular ones.

    Also consider FromSql and Find

  9. changed the title [-]Expose batching read API to users[/-] [+]Execute multiple LINQ queries in a single round-trip (aka Expose batching read API to users)[/+] on Aug 15, 2022
  10. ziaulhasanhamim commented on Sep 9, 2022

    @ziaulhasanhamim

    Will this feature ever arrive?

  11. 26 remaining items

  12. added theissue type on Jun 15, 2025
  13. marked Creating QueryTask #22002 as a duplicate of this issue on Jun 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions