简体   繁体   中英

Entity Framework Update without reading

Is there a way to update a single table / entity without having to read the entity first into a list. This is the sql I am trying to achieve.

Update table set col1 = Case col2 When 0 then 1 else 0 end this updates roughly 500,000 records under a second

I do not want to do

 List<table> updRecs = Context.tables.toList();
 for each
 {
  if(col1 == 0)
  col2 = true 
  else
  col2 = false
 }

Context.SaveChanges();

above is very slow roughly 4 minutes.

EntityFramework.Extended

nuget

git

context.Tasks
    .Where(t => t.StatusId == 1)
    .Update(t => new Task { StatusId = 2 });

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