Sembra facile, vero? Ecco lo scenario ...Come aggiornare un'entità in EF su più richieste ASP.NET senza recuperarlo di nuovo?
Private dbQuery As New ReefEntities
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
CurrentCoral = (From c In dbQuery.Corals Where c.CoralID = intCoralID).FirstOrDefault
txtCommonName.Text = CurrentCoral.CommonName
End If
End Sub
Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
'how do I access the coral from the page load to update it?
CurrentCoral.CommonName = strName
dbQuery.SaveChanges()
End Sub
Non voglio ri-query mio risultato, voglio aggiornare la query dal caricamento della pagina e quindi salvare le modifiche, giusto? Come posso accedere a quell'oggetto originale per aggiornarlo?