Вот моя проблема: я использую Silverlight + WCF RIA + EntityFramework и источник данных домена. Я вставляю на стороне клиента родительскую сущность, а затем дочернюю сущность (у родителя может быть много дочерних элементов) следующим образом:
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)
Как я могу контролировать порядок вставки на стороне сервера или что я делаю неправильно?
Спасибо за любую помощь.
Child
в родительском элементе аннотированной[Composition]
? Можете ли вы поделиться кодом, который определяет сущности? - person Ed Chapel   schedule 06.07.2012