How to Bulk Update records in Entity Framework?

前端 未结 7 2207
遥遥无期
遥遥无期 2020-12-01 08:00

I am trying to bulk update records using Entity Framework. I have tried Entity Framework.Extensions Update method.

The Update method is abl

7条回答
  •  醉酒成梦
    2020-12-01 08:35

    Use ExecuteSqlCommand:

    using (yourDbEntities db = new yourDbEntities())
    {
        db.Database.ExecuteSqlCommand("UPDATE YourTABLE SET Quantity = {0} WHERE Id = {1}", quantity, id);
    }
    

    Or ExecuteStoreCommand:

    yourDbContext.ExecuteStoreCommand("UPDATE YourTABLE SET Quantity = {0} WHERE Id = {1}", quantity, id);
    

提交回复
热议问题