Update on 2mil records Customers how to do a single update instead of 2k separately

7

I have a Client Model and need to update on EnviadoEmailCobranca para 0

I'm doing this:

    var clientes = db.Clientes.Where(w => w.Status == 4);

    foreach (var item in clientes)
    {
        item.EnviadoEmailCobranca = false;

        db.Entry(item).State = EntityState.Modified;
        db.SaveChanges();
    }

But this is kind of donkey , since I'm doing 2mil updates separately. There is something like:

Update tabela_Clientes where EnviadoEmailCobranca=0 where Status =4

I did not want to do this:

var SQL = "Update tabela_Clientes where EnviadoEmailCobranca=0 where Status =4";
dbMailEnable.Database.ExecuteSqlCommand(SQL);
    
asked by anonymous 10.03.2016 / 16:14

1 answer

7
  

How to make a single update instead of separate 2k?

Not using the native Entity Framework. That simple. It does not meet this kind of demand you have.

EntityFramework.Extended already attend , as it has batch update implemented. His NuGet package is here .

Usage:

db.Clientes
  .Where(w => w.Status == 4)
  .Update(w => new Cliente { EnviadoEmailCobranca = 0 });
    
10.03.2016 / 16:47