Entity Framework - Add reference to child object without retrieving entire list of objects?

Server doesn't know if entity exists until it loads it from database. So when you add childs on client and send them to the server you also have to include information about new childs, updated childs and deleted childs. If you do not include such information you have to load complete entity graph from DB first and then compare received graph with loaded graph and process changes manually Automatic solution for such case can be Self tracking entities (STEs) but still your example will not work.

STEs require you to load objects, send them to client, modify them and send them back. STEs will track all changes.

Server doesn't know if entity exists until it loads it from database. So when you add childs on client and send them to the server you also have to include information about new childs, updated childs and deleted childs. If you do not include such information you have to load complete entity graph from DB first and then compare received graph with loaded graph and process changes manually.

Automatic solution for such case can be Self tracking entities (STEs) but still your example will not work. STEs require you to load objects, send them to client, modify them and send them back. STEs will track all changes.

I am using STE's and currently I have to get all children from the server then client side add them i.e. Parent.children. Add(child) (where child is one that I received from the server).

It sounds like this is the only way to do this with STE's (is this correct? ) I wanted to just parent.children. Add(new child(childid=1)) would work as when it goes to save to the db it would see that there is already a child with an id of 1 and not create a new one.

– David Dec 9 '10 at 1:50.

Using(var context = new MyEntities()) { var child1 = new Child{ childId = 1 }; context.Children. Attach(child1); var parent = new Parent(); parent.Children. Add(child1); context.SaveChanges(); }.

I am working through a wcf service with entity objects and so client side there isn't any such thing as 'context' – David Dec 28 '10 at 17:25.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions