I have the following code:
List<Item> csItems = (from i in context.Items
where i.CSItem == true
select i).ToList<Item>();
csItems.ForEach(i => i.Active = false);
context.SaveChanges();
Seems like this is horribly inefficient as I have to read the entire table in first, then update the tables. Is there a better way to do this so that I am only doing an update without reading everything?
There is no need to build the
List<T>of the items. I, personally, would just enumerate the results and set the values:Note that there is no bulk-update functionality built-in with Entity Framework, so doing something more efficient would require some other technique.