views:

390

answers:

1

Hi,

I am using silverlight client with ado.net dataservices on entity framework.

I have an Entity Contact and an Entity Address which is related with a foreign key relation ship... A contact can have 1 or more Adresses but a Address needs always at least 1 contact.. pretty basic...

I have a Repository for my contacts and Address which has a Method Add(T entity),...

On my Client I have a form with allows users to add a contact with an address

and I want to save both away to the database...

Address a = new Address();
a.Street="Street",
a.City = "City"
a.Contact = 
 new Contact(){ Name="Name",Age="60"}

_repository.Add(a);

....

Ok i figured out that I can not save a related object graph right away so i did something like this

DataBaseEntities.AddToContact(obj2Badded.Contact);
DataBaseEntities.AddToAddress(obj2Badded);
DataBaseEntities.SetLink(obj2Badded,"Contact",object2Badded.Contact);
DataBaseEinties.BeginSaveChanges(...)

Is there away to do this in transations like when contact is not added address will also not be added and vice versa...

... and all what I have tried is not working...

It would be great if someone can point me in the right direction on this topic I simply want to add a related object graph =} ...

A: 

Your first example should work just fine, related entities and all. There is no need to add related entities to the context separately, if you are inserting new objects for both of them. So unless you tell us what the problem is when you ran this code, it will be hard to help.

Craig Stuntz