Update a collection in C#
I'm trying to update some records in a collection, but I have issues updating it.
If I use this example:
from c in Customers
select
from p in c.Purchases
select new { c.Name, p.Price }
How can update the price?
thanks so much for your help.
Rachida
If I use this example:
from c in Customers
select
from p in c.Purchases
select new { c.Name, p.Price }
How can update the price?
thanks so much for your help.
Rachida
Comments
I'm assuming you have a database containing the tables Customers and Purchases. If that's the case, make sure your tables have a primary key and there exists a foreign key relationship between the two. You can create sample tables with the SQL script below. You will notice that LINQPad will put additional navigational properties in the schema explorer, like CustomerPurchases. If you change your code to the code below, you will get a list of items. Clicking ono each item, you can see the individual customer records, including purchase prices: Now, to update a price of a purchase, select the purchases you are interested in. When you have applied the update, make sure you'll execute SubmitChanges(), like in the following code: However, a much easier way is to navigate form the many side to the 1 side of the relationship. The following code will establiwsh exactly the same thing, but with far less ceremony: HTH,
Arno