Updating using linq
The following example shows how to combine two in-memory data structures, but the same principles can be applied to combine data from XML or SQL or Data Set sources.Assume the following two class types: For more information, see Object and Collection Initializers and Anonymous Types.LINQ to SQL offers maximum flexibility in manipulating and persisting changes that you made to your objects. As soon as entity objects are available (either by retrieving them through a query or by constructing them anew), you can change them as typical objects in your application. Contact Name = "New Contact"; // Create and add a new Order to the Orders collection. Furthermore, the output sequence of one query can be used as the input sequence for a new query.
All linq-methods don´t modify the underlying collection, they just , however it simply hides it from the client.
To clarify, I want to iterate through each object in a collection and then update a property on each object.
My use case is I have a bunch of comments on a blog post, and I want to iterate through each comment on a blog post and set the datetime on the blog post to be 10 hours.
Language-Integrated Query (LINQ) is not only about retrieving data. By using a LINQ query, you can use a source sequence as input and modify it in many ways to create a new output sequence.
You can modify the sequence itself without modifying the elements themselves by sorting and grouping.