简体   繁体   English

实体框架更新,无需阅读

[英]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. 这是我正在尝试实现的sql。

Update table set col1 = Case col2 When 0 then 1 else 0 end this updates roughly 500,000 records under a second 更新表集col1 =案例col2如果为0,则为1,否则为0,这将在一秒钟内更新大约500,000条记录

I do not want to do 我不想做

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

Context.SaveChanges(); Context.SaveChanges();

above is very slow roughly 4 minutes. 以上大约4分钟非常慢。

EntityFramework.Extended EntityFramework.Extended

nuget 裸体

git 吉特

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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