0
votes

I have a List of an Entity for e.g List of Customer entity.

I am using a Bulk update as context.Customer.UpdateRange(Customer);

My requirement is I need to increment an Existing Column value with a new value. for e.g Inside Customer table Qty column needs to be updated as Qty = Qty + current_Value.

I can do this by looping through the Customer List and update the column one by one customer object. But I wish to do this while bulk update (UpdateRange)

The technology I am using - ASP.NET Core, MVC Core, EF Core

1

1 Answers

1
votes

The DbContext.UpdateRange method only marks your entities' states as Modified. This way, each entity will be updated, no matter if the data has changed or not (https://docs.microsoft.com/en-us/dotnet/api/microsoft.entityframeworkcore.dbcontext.updaterange?view=efcore-2.1).

This method is not supposed to be used to iterate the list of entities and to change its values.

Knowing that you have several solutions :