Skip to content

Switch to using the new batching API #1922

Open

Description

@roji

Our batching implementation currently uses NpgsqlCommand with legacy batching. Once dotnet/efcore#18990 is implemented, switch to using that (search for all suppressions of 618, obsolete API usage).

Activity

  1. added this to the 7.0.0 milestone on Jul 19, 2021
  2. self-assigned this
    on Jul 19, 2021
  3. modified the milestones: 7.0.0, 8.0.0 on Oct 15, 2022
  4. modified the milestones: 8.0.0, Backlog on Nov 13, 2023
  5. added theissue type on Jun 14, 2025
  6. yanw-bq commented on Aug 1, 2025

    @yanw-bq

    Hi @roji , I was wondering if there’s any update on this issue—has work on switching to the new batching API started, or is there a rough timeline for when it might be addressed?

  7. roji commented on Aug 2, 2025

    @roji
    MemberAuthor

    @yanw-bq what's you reason for asking, how specifically are you expecting this work to impact you?

  8. yanw-bq commented on Aug 7, 2025

    @yanw-bq

    Hi @roji,

    Thanks for your earlier response!

    We're currently building our own EF Core provider on top of efcore.pg, and as part of that, we're replacing the IRelationalConnection service with our own implementation. While doing so, we noticed an explicit cast to NpgsqlDataReader in NpgsqlModificationCommandBatch, which is used to access the Statements property.

    Since Statements is now marked obsolete with the note to use the new DbBatch API, we believe our issue might be resolved once this GitHub issue is completed.

    Would there be any chance we could contribute to this effort? We'd be happy to help move it forward if that's possible.

    Thanks again for your work and for considering our request!

  9. roji commented on Aug 8, 2025

    @roji
    MemberAuthor

    If this is just about referencing the obsolete NpgsqlDataReader.Statements, then I'd recommend simply suppressing the warning as we do in NpgsqlModificationCommandBatch - that's just how things are at the moment. I'm definitely interested in having EF use DbBatch (not just for Npgsql/PG), but the obsoletion warning isn't really a strong reason for that (there are others).

    Doing this probably won't be trivial. If you're interested in taking a stab at it, please take a look at the code first and post a quick proposal of what you intend to do before doing actual work and submitting a PR.

  10. yanw-bq commented on Aug 14, 2025

    @yanw-bq

    Hi @roji,

    Thanks again for the clarification! I think there might have been a small misunderstanding—just to clarify, the warning itself isn’t an issue for us either.

    The challenge we’re facing is with the explicit cast to NpgsqlDataReader in NpgsqlModificationCommandBatch. Since we’re replacing the underlying reader with our own implementation, this cast becomes problematic.

    We were hoping that the switch to the new batching API might eliminate the need for that cast, and thus resolve our issue. But it’s possible we misunderstood the direction of the change.

    Would you happen to know if the new batching API would indeed remove that dependency on NpgsqlDataReader, or if it’s likely to remain?

    Thanks again for your time and insights!

  11. roji commented on Aug 15, 2025

    @roji
    MemberAuthor

    @yanw-bq the batching reader should indeed remove the cast to NpgsqlDataReader in that particular spot, but I can't say off the top of my mind whether there are others where specific features of NpgsqlDataReader (or NpgsqlConnection, or NpgsqlCommand...) are being used.

    I don't know your reaosns for needing to replace NpgsqlDataReader, but as an alternative you may want to implement your special logic inside EF itself rather than inside NpgsqlDataReader (RelationalDataReader in EF is the wrapper around DbDataReader, and could be a better place to customize with your logic).

  12. yanw-bq commented on Aug 27, 2025

    @yanw-bq

    Hi @roji,

    Thanks again for the continued discussion!

    Just to clarify our situation a bit more: we're building a wrapper around NpgsqlConnection and NpgsqlDataReader, and we’d like our custom driver to remain compatible with efcore.pg. The issue we’re facing is that the explicit cast to NpgsqlDataReader in NpgsqlModificationCommandBatch attempts to cast our wrapper reader, which obviously fails.

    We’re hoping that the transition to the new batching API might remove the need for that cast, but if not, we’d love to explore alternative approaches. We’re also interested in contributing to this issue and plan to put together a proposal once we have some time to dive deeper.

    We’ll keep you updated—thanks again for your time and support!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions