Hi Arjang,

Have you installed the `Reactive Extensions for .Net (Rx)`
(http://social.msdn.microsoft.com/Forums/en-US/rx/threads)?

It gives you, not only the support for `IObservable<T>/IObserver<T>` for
push collections and a back-port of the TPL for .NET 3.5SP1, but it also
gives you a ton of extensions for `IEnumerable<T>`.

You get two extension methods that answer your question.

`.Run(Action<T>)` lets you write this code:

var names =
    from p in nameList
    where p.FirstName == "Pater"
    select p;

names.Run(p => p.FirstName = "Peter");

`.Do(Action<T>)` works like `.Run(Action<T>)` but it returns the list so can
be used inside a LINQ query like this:

var names =
    (from p in nameList
     where p.FirstName == "Pater"
     select p).Do(p => p.FirstName = "Peter");

or:

var names = nameList
    .Where(p => p.FirstName == "Pater")
    .Do(p => p.FirstName = "Peter");

Cheers.

James.

-----Original Message-----
From: [email protected] [mailto:[email protected]]
On Behalf Of Arjang Assadi
Sent: Friday, 25 February 2011 12:07
To: ozDotNet
Subject: Linq (To Objects) Update ( like sql )

When using Linq to Objects, is it possible to change a property value
on all the selected values?
I am NOT using Linq to sql, I have list items and want to change value
of some properties depending on names e.g.

//typo in name entry, can not change the persisted data, instead
correcting in code, there are no ID's to create a correction table for
specific records, just having to hard code it heuristics.

var names = from p in nameList
                  where p.FirstName == "Pater"
                  set p.FirstName = "Peter"
                  select p;

Regards

Arjang

Reply via email to