我正在使用組合屬性。最近,我來到了以下博客:WCF RIA Services v1 sp1,組成,驗證子實體
http://brettsam.com/2011/03/25/ria-services-composition-with-entity-framework/
所以,我用在上面的博客文章介紹的方法來糾正我的孩子實體的實體狀態如下所示:
foreach (Child c in this.ChangeSet
.GetAssociatedChanges(currentParent, p => p.Children))
{
ChangeOperation change = this.ChangeSet.GetChangeOperation(c);
switch (change)
{
case ChangeOperation.Delete:
...
case ChangeOperation.Insert:
// This is already done for us.
break;
case ChangeOperation.None:
...
case ChangeOperation.Update:
this.ObjectContext.Children
.AttachAsModified(c, this.ChangeSet.GetOriginal(c));
break;
default:
break;
}
}
我也刪除了默認生成的UpdateChild(Child currentChild)方法。 現在,代碼工作並將子實體按預期保存到數據庫。不過, 我注意到一個問題。我的子實體的一些屬性具有自定義驗證屬性 (從ValidationAttribute類繼承)。他們根本沒有被叫到。這個自定義的 驗證屬性不會在silverlight客戶端生成,因爲它使用了一些僅在.NET中可用的類。但不是在silverlight。所以,在 客戶端驗證通過,並且服務器端也不驗證。但是,如果 我將UpdateChild方法添加回DomainService,則會運行驗證屬性的代碼。 這裏有什麼問題?有人可以解釋這個嗎?