我有一个Silverlight 4 RIA域服务。在一个特定的方法中,我需要在数据库中更改一个值(当然是其他事情)。要执行此操作,我得到实体,更改一个值,然后我需要将其保存回DB。

我已经尝试呼叫实体的生成更新函数,只需调用它.ObjectContext.myentity.attachasmodifed(无神透);但更改永远不会回到数据库。

如何将值从服务器端保存(即,客户端从未有此数据)?

有帮助吗?

解决方案 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
    }
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top