开发者

Possible to update a member for all objects in a collection using LINQ?

开发者 https://www.devze.com 2023-01-07 12:22 出处:网络
Say I have the code below that uses LINQ to SQL: MyDataContext dc = new MyDataContext; var items = from f in dc.TableName

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();
0

精彩评论

暂无评论...
验证码 换一张
取 消