简体   繁体   中英

How does Entity Framework Extended batch Update method deal with default values?

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, eg 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM