Tuesday, 15 May 2012

c# - Not able to Update the LINQ list -


I have a list of products from the database and from this list, I used LINQ and a list of phones Returned class as a form.

Listings & gt; Products & gt; Products = new list & lt; Products & gt; New product {ID = 1, name = "alcohol"} has expired, new product {id = 2, name = "phone", expired = false}, new product {id = 2, name = " Phone "expired = false}, new product {id = 3, name =" computer ", expired = false}, new product {id = 4, name =" president ", time expired}}} ; In the products from Var results = i Where (o = & gt; o.Name == "phone") select new phones {id = i.id, phone = i.Name, isChild = i.Expired}; // ischild property foreach update (var item in result) {item.ischild = true; } Public category phones {get public id ID {. Set; } Public string phone {get; Set; } The public is Bull Children {Go; Set; }}

I used to update the list of phones using the foreach loop. But the problem is that when I checked the result variable it did not update the said item.

Because try to execute your results of deferred execution of IEnumerable, execute the query: < / P>

  var results = (i.e. products (where o = & gt; o.name == "phone") new phones {id = iid, phone = i.Name, isChild = I.Expired}). ToList ();  

If you will not - this will require products every time and you will work with new phones.


No comments:

Post a Comment