I am using GraphDiff along with the latest Entity Framework, following the first code approach.
I am trying to update an object Foodas follows:
public void Update(Food food)
{
using (var db = new DatabaseMappingContext())
{
food = db.UpdateGraph(food, map => map.OwnedEntity(f => f.FoodRecipe, withRecipe => withRecipe.
OwnedCollection(r => r.RecipeSteps, withRecipeStep => withRecipeStep.
OwnedCollection(rs => rs.StartObjectSlots, withStartObjectSlots => withStartObjectSlots.
AssociatedEntity(sos => sos.BelongingRecipeStepAsStart)
).
OwnedCollection(rs => rs.EndObjectSlots, withEndObjectSlots => withEndObjectSlots.
AssociatedEntity(eos => eos.BelongingRecipeStepAsEnd)
).
AssociatedEntity(rs => rs.ActionOfUser)
).
AssociatedCollection(r => r.InteractiveObjects)
).
AssociatedCollection(f => f.FoodVarieties));
db.SaveChanges();
}
}
StartObjectSlotsand EndObjectSlots- 2 lists containing some other irrelevant data.
InteractiveObjectscontains objects of a type InteractiveObject, which is the base type for several types of objects that can be placed there. One of these derived types (for example, IntObjDerivedhas a "one-to-many"). Now I am trying to update the following object as follows:
ServerAdapter sa = new ServerAdapter();
Food food = sa.LoadAllFoods().First();
RecipeStep rs = new RecipeStep();
rs.Name = "This is a test recipe step";
rs.ActionOfUser = sa.LoadAllUserActions().First();
food.FoodRecipe.RecipeSteps.Add(rs);
sa.Update(food);
Now, when the code is executed, a new empty ActionOfUser object is inserted into the database. Besides, " " . , , . , . , . - ?
( , , -, 2 , , , - ).
EDIT: GraphDiff, , , , , Entity ID.
, , node ( RecipeStep), , graphdiff.
UPDATE (tl; dr version): UpdateGraph, Entity Framework GraphDiff 2.
, , , GraphDiff 2, , node , . , , UpdateGraph ?
!