Possible to update a member for all objects in a collection using LINQ?
Say I have the code below that uses LINQ to SQL:
MyDataContext dc = new MyDataContext;
var items = from f in dc.TableName
where f.ChildId == 4
select f;
开发者_如何学编程If the table TableName has a column called Completed
is it possible for me to set the Completed
column to true
for everything selected above?
You'll have to load the results of your query into a variable. You can then modify each object as you like, and then simply SubmitChanges()
.
MyDataContext dc = new MyDataContext;
var items = dc.TableName.Where(f=>f.ChildId == 4).ToList();
items.ForEach(i=> i.Completed = true);
dc.SubmitChanges();
精彩评论