adding data for many to many tables

Mar 27, 2011 at 4:51 PM
Edited Mar 27, 2011 at 4:57 PM

hello,

I have created associative table for many to many relationship tables .

but how do i add, edit, remove data to the associative entities using the API ?

using the Car- Feature example can you give us examples for adding, removing and editing instances to associative tables?

Regards

Giannis

Mar 31, 2011 at 5:33 PM
Edited Mar 31, 2011 at 5:33 PM

To Remove

Dim c as Car = SelectByPk(CarId)

Dim p as Person = SelectByPk(PersonId)

if p.CarList.Contains(c) then

p.CarList.Remove(c)

p.parentCollection.persist

end if

 

To Add

Dim c as Car = SelectByPk(CarId)

Dim p as Person = SelectByPk(PersonId)

if NOT p.CarList.Contains(c) then

 p.CarList.Add(c)

p.parentCollection.persist

end if

Mar 31, 2011 at 6:37 PM

thanks, it works.

i was using

p.persist

instead of

p.parentcollection.persist

which was causing me trouble.

Coordinator
Mar 31, 2011 at 11:02 PM

This does work. Actually you can call the persist of any collection. They all save the subdomain. So you can call persist on the CarCollection or the PersonCollection and it makes no difference. There are two types of save using the ADO.NET DAL single row and entire subdomain. Remember that the subdomain is container for one or more collections. There is always a subdomain present if you have a collection.