ドメインサービス - サーバーサイドアップデート
-
14-11-2019 - |
質問
私はSilverlight 4 RIAドメインサービスを持っています。特定の方法では、データベース内の1つの値を変更する必要があります(もちろん)。これを行うには、エンティティを取得し、1つの値を変更してから、その変更をDBに戻す必要があります。
エンティティの生成されたアップデート関数を呼び出してみました。しかし、変更はデータベースに戻ることはありません。
サーバー側から値を保存する方法(すなわち、クライアントはこのデータを持っていない)?
解決 2
Turns out, attaching the object before or after the change makes no difference. The missing peice was :
this.ObjectContext.SaveChanges();
他のヒント
You should know that the UpdateXXX method doesn't actually submit the changes to the database - that only happens a bit later. knowing this, we can change the default implementation of the UpdateXXX method: (I'm assuming XXX == Product here)
public void UpdateProduct(Product currentProduct)
{
this.ObjectContext.Products.AttachAsModified(currentProduct, this.ChangeSet.GetOriginal(currentProduct));
}
to
public void UpdateProduct(Product currentProduct)
{
// This line only reattach the entity back to EF context, it doesn't submit changes yet
this.ObjectContext.Products.AttachAsModified(currentProduct, this.ChangeSet.GetOriginal(currentProduct));
currentProduct.SomeProperty = "SomeChange"; // This change is going to be submitted later
}
所属していません StackOverflow