Entity Framework Update without reading

c# entity-framework entity-framework-6

Question

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.

1
0
10/28/2015 3:52:23 PM

Accepted Answer

EntityFramework.Extended

nuget

git

context.Tasks
    .Where(t => t.StatusId == 1)
    .Update(t => new Task { StatusId = 2 });
1
10/28/2015 3:56:40 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow