I'm using Entity Framework Extended to perform a batch update just like the example below from its official documentation (https://github.com/loresoft/EntityFramework.Extended/wiki/Batch-Update-and-Delete):
//update all tasks with status of 1 to status of 2
context.Tasks
.Where(t => t.StatusId == 1)
.Update(t => new Task { StatusId = 2 });
It works, but I'd like to know the inner workings. How does it deal with the default values of the Task
object. Let's say it has a property called MyProperty
which is an int
that defaults to 0
. When a Task
object is initialized, it's MyProperty
value will have the default value of 0
. How does Entity Framework Extended distinguish between MyProperty
having the default value of 0, or if I'm trying to set MyProperty
of all matched objects to their default value of 0, e.g. new Task { StatusId = 2 , MyProperty = 0}
as the created Task
object will be exactly the same in each case?
When you pass this:
.Update(t => new Task { StatusId = 2 });
You are not creating a Task
object at all. You are passing in an expression which the batch updater is parsing (and not executing at all). The new Task { StatusId = 2 }
is never executed.