7
I have a Customer Model and need to do an update on EnviadoEmailCobranca para 0
I’m doing like 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 that’s kind of donkey, because I’m doing 2,000 separate updates. There is something like:
Update tabela_Clientes where EnviadoEmailCobranca=0 where Status =4
I didn’t mean to do it like this:
var SQL = "Update tabela_Clientes where EnviadoEmailCobranca=0 where Status =4";
dbMailEnable.Database.ExecuteSqlCommand(SQL);
I even took it out, but the performance was far from reasonable.. I did a test with 6,000 records and it took a lot longer than doing a direct Executesqlcommand...
– Dorathoto