Saving M:N relation

Posts   
 
    
Fanaticit
User
Posts: 4
Joined: 09-Oct-2007
# Posted on: 09-Oct-2007 11:44:31   

I wanted to find out if there was a clean way to save the parent object and have it save the children in the following structure:

Person -> PersonAddress -> Address

Here is the sample code.


            DataAccessAdapter adapter = new DataAccessAdapter(connectionString);
            PersonEntity person = new PersonEntity(4);

            PrefetchPath2 prePath = new PrefetchPath2((int)EntityType.PersonEntity);
            prePath.Add(PersonEntity.PrefetchPathAddressCollectionViaPersonAddress);
            
            adapter.FetchEntity(person, prePath);
            person.AddressCollectionViaPersonAddress.IsReadOnly = false;

            // add an address
            AddressEntity address = new AddressEntity();
            address = person.AddressCollectionViaPersonAddress.AddNew();
            address.AddressTypeId = 1;
            address.Line1 = "Bla";
            address.Line2 = "Bla";
            address.Line3 = "Bla";

            adapter.SaveEntity(person, true, true);

If I SaveEntityCollection it saves the new Address but not the PersonAddress?