Reputation: 247
Here's my problem : I'am using Silverlight+ WCF RIA + EntityFramework and domain datasource. I'am inserting on the client side a parent entity and then a child entity (a parent can have many children) like this :
Parent p = new Parent();
p.PropertyA = "MyTest";
if (!this.domainContext.Parents.Contains<Parent>(p))
this.domainContext.Parents.Add(p);
Child c = new Child();
c.PropertyOfC = "Togodo";
if (!this.domainContext.Childs.Contains<Child>(c))
this.domainContext.Childs.Add(c);
c.parent = p;
p.Child.Add(c);
// Submit update RAISE ERROR
domainContext.SubmitChanges(submitOp =>
{
// Declare error
Exception error = null;
// Set error or result
if (submitOp.HasError)
{
error = submitOp.Error;
}
// Invoke completion callback
if (completed != null)
completed(error);
}, null);
}
When I call the "submitChanges", on the serveur side, the "insert method" of the child enity is called before the parent one. So an exception occurs due to foreign key constraint. The code here is simplified. On the real case, I can't call submit changes twice (one after created the Parent Entity, and one after the child creation)
How can I control the insert order on server side, or what I'am doing wrong ?
Thanks for any help.
Upvotes: 0
Views: 508
Reputation: 247
Thanks for your help but I found the problem.
In fact I was inserting the parent entity through stored procedure and I haven't correctly configure the "output result binding" of the Id. So the parent Id was not correctly updated on my entity model after insertion on the database.
Upvotes: 0