Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The context is not permanently connected to the database. It is essentially an in-memory cache of records you have loaded from disk. It will only request records from the database when you request a record it has not previously loaded, if you force it to refresh or when you're saving your changes back to disk.</p> <p>Opening a context, grabbing a record, closing the context and then copying modified properties to an object from a brand new context is the epitomy of redundant code. You are supposed to leave the original context alone and use that to do SaveChanges().</p> <p>If you're looking to deal with concurrency issues you should do a google search about "handling concurrency" for your version of entity framework.</p> <p>As an example I have found <a href="http://www.dotnetrangers.net/2011/10/17/code-first-with-entity-framework-4-1-part5-concurrency-management/" rel="nofollow">this</a>.</p> <p><strong>Edit in response to comment:</strong></p> <p>So from what I understand you need a subset of the columns of a record to be overridden with new values while the rest is unaffected? If so, yes, you'll need to manually update these few columns on a "new" object. </p> <p>I was under the impression that you were talking about a form that reflects all the fields of the customer object and is meant to provide edit access to the entire customer record. In this case there's no point to using a new context and painstakingly copying all properties one by one, because the end result (all data overridden with form values regardless of age) will be the same.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload