views:

28

answers:

1

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?

+2  A: 

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();
p.campbell