Pergunta

Eu tenho um serviço de domínio do Silverlight 4 Ria.Em um método particular, preciso alterar um valor no banco de dados (entre outras coisas, claro).Para fazer isso, obtenho a entidade, mude o valor, então preciso salvar essa mudança de volta para o dB.

Eu tentei ligar para a função de atualização gerada da entidade, que apenas chama isso.ObjectContext.myentity.attachaSmodificada (Myentity);Mas a mudança nunca volta para o banco de dados.

Como faço para salvar valores do lado do corte (ou seja, o cliente nunca teve esses dados)?

Foi útil?

Solução 2

Turns out, attaching the object before or after the change makes no difference. The missing peice was :

this.ObjectContext.SaveChanges();

Outras dicas

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
    }
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top