Entity Framework Feature Suggestions

Batch CUD support

When SaveChanges is called, rather than sending one SQL statement per insert/update/delete, batch it all up into one SQL statement

2,962 votes
Vote
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    I agree to the terms of service
    Signed in as (Sign out)
    You have left! (?) (thinking…)
    Mike FlaskoMike Flasko shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →
    planned  ·  Diego VegaAdminDiego Vega (Development Lead, DataFx) responded  · 

    UPDATE: We do plan to implement batch CUD support in the EF7 codebase. We are just not committed yet to doing it for the initial RTM and we are currently not actively working on it.

    Reverting status from “under review” to “no status” since we aren’t currently working on this. We will still consider it for future releases.

    18 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      I agree to the terms of service
      Signed in as (Sign out)
      Submitting...
      • Diego VegaAdminDiego Vega (Development Lead, DataFx) commented  ·   ·  Flag as inappropriate

        Hi Raffaele,

        EF7 will target many cloud and enterprise scenarios besides devices. See this announcement for more details on our plans: http://blogs.msdn.com/b/adonet/archive/2014/05/19/ef7-new-platforms-new-data-stores.aspx.

        We would love to have batch CUD ready in EF 7 RTM but since we have a lot of other work to do to complete EF7 we are trying to set expectations carefully.

        Anyway, thanks for expressing how important this is to you. That always helps!

      • Raffaele RialdiRaffaele Rialdi commented  ·   ·  Flag as inappropriate

        Frankly, given this decision, I am not sure it's worth the upgrade until batch isn't there.
        I understand EF7 is primary targeted for devices but enterprises need this before any other feature and they should (still?) be considered important drivers for new features.
        I am realistic, please don't take my comment as polemic.

      • Roger HendriksRoger Hendriks commented  ·   ·  Flag as inappropriate

        Hope you will consider it soon. Strange that EntityFramework.Extended and BulkInsert exists and are know in the EF community and MS cannot make speed on this crucial functionality for high performance business apps. Please connect to the business developers more! If you don't use ExtendedNow you need to use 2 paradigma's, linq and ExecuteStoreCommand sql...... And AddRange and RemoveRange still generates 1 statement per entity instance :(

      • Raffaele RialdiRaffaele Rialdi commented  ·   ·  Flag as inappropriate

        Do you refer to EF6 or EF7?
        I guess batch support is the very number one request in every training I gave about EF ...

      • Randall WillisRandall Willis commented  ·   ·  Flag as inappropriate

        This is incredibly important. we have not been able to adopt EF because its detractors on our team simply pop open sql profiler and point to its "chattiness" (we have db servers in several geographies), to which there has yet been no acceptable reply. If this problem were able to be solved, I believe this technology would open up to many enterprise level teams who are just waiting on the sidelines. Smaller applications would benefit as well.

      • Gaëtan Voyer-PerraultGaëtan Voyer-Perrault commented  ·   ·  Flag as inappropriate

        I'm actually going to put in a couple of points about why this is a *bad idea*.

        1. It assumes that the DB correctly supports a bulk update process. This may not be true for some database that plug into EF. How does bulk delete work in CouchDB?
        2. It conflates two issues.
        a. DB-specific Optimizations.
        b. The ability to send mass-update operations to the DB.

        At best we may want to put expose a hook, but from what I can tell that "hook" already exists. Maybe if there was a ready "plug-in" model so that I could include "SQL Server Bulk Inserter" and then plug it in this may be a more sustainable direction.

        Likewise several of the comments conflate "Bulk insert" with "Perform SQL Operation". These are clearly different things as again, not everything on the other end of EF may support "DELETE x WHERE " syntax.

      • mohammadmohammad commented  ·   ·  Flag as inappropriate

        This is very important feature that ef not suport that , :(
        batch insert , delete

      • Anonymous commented  ·   ·  Flag as inappropriate

        This is a much needed feature in EF. Performance may be critical for some applications. EF Extended already supports this (except batch insert), so why not do it? Many people need this. We work in places where the connection suffers from many time outs and has high latency. Please do something about this. It must mean something that it is the most voted feature here :)

      • Todd AspeotisTodd Aspeotis commented  ·   ·  Flag as inappropriate

        Although we're using EF in another projects I left it out of a recent one in favour of stored procedures, table valued parameters and the MERGE statement. Lots of rows to deal with here and little time to deal with them in. EF was not suitable.

        Turns out parameter sniffing on the stored procedures hurt things a bit, but I imagine EF could skip the SPs and go straight for SQL statements (much the same way it is now). Beyond that the SPs follow a bit of a formula.

        Only thing to do would be to create a user defined table type for each entity and figure out how to efficiently insert dependent objects. You'd have basic batch CUD there.

        Perhaps it would be difficult to return meaningful error messages when using MERGE vs. individual statements but I'd opt-in to that pain for the performance improvements.

      • Anonymous commented  ·   ·  Flag as inappropriate

        you should look at odp.net provider for oracle, as it has this facility to do this, and you can actually place an array of input parameters to the stored procdure. Then do one single transaction to update the table with these values. It would be really handy to have than having to keep going up and down the network - especially useful for performance !

      • Ruwan WijesingheRuwan Wijesinghe commented  ·   ·  Flag as inappropriate

        It is ideal if you can support bulk updates and deletes like below,

        query.Update(entity => new { prop1 = 10, prop2 = entity.prop2 + 10});
        query.Delete();

      • vanvan commented  ·   ·  Flag as inappropriate

        Bulks Insert/Update/Delete is a real performance problem in EF seeing as there is no real support for bulk. This is my most needed feature right now.
        Even if the entity model supported the DBType.Structured it would help a lot. Then you would be able to pass a data table to a stored proc. But at the moment you have to create a new SqlConnection to do this, which is not cool.

      • alaa9joalaa9jo commented  ·   ·  Flag as inappropriate

        also we want it to support conditional update/delete,i.e.:

        UPDATE TableName
        SET Column1 = ‘Value’
        WHERE AnotherColumn = ‘AnotherValue’

      Feedback and Knowledge Base