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,819 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 →

    12 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...
      • 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