Domanda

Ho un servizio dominio Silverlight 4 RIA.In un metodo particolare ho bisogno di cambiare un valore nel database (tra le altre cose, naturalmente).Per fare ciò ottengo l'entità, cambia il valore un valore, quindi ho bisogno di salvare quel cambiamento sul DB.

Ho provato a chiamare la funzione di aggiornamento generata dalla entità, che chiamano solo questo.ObjectContext.Myenty.attachasmodified (Mieriet);Ma il cambiamento non torna mai al database.

Come faccio a salvare i valori dal lato sever (cioè il cliente non ha mai avuto questi dati)?

È stato utile?

Soluzione 2

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

this.ObjectContext.SaveChanges();

Altri suggerimenti

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
    }
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top