Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think you misunderstood <em>MergeOption.OverwriteChanges</em>. By default, anytime the <em>ObjectContext</em> performs a query, if any of the returned objects already exist in the cache the newly returned copies of those objects are ignored. <br><br> Please note that it all happens based on the <strong>EntityKeys</strong>. Basically the EntityKeys of the objects returned from a query are checked, and if an object with the <strong><em>same</em></strong> EntityKey (in the same EntitySet, in your case, <em>Lectures</em>) already exists in the cache, the existing object is left untouched. <br><br> However, if you enable <a href="http://msdn.microsoft.com/en-us/library/system.data.objects.mergeoption.aspx" rel="noreferrer"><em>OverwriteChanges</em></a>, then it will <em>Replace</em> the current values of existing entities with values coming from the database, even if the in-memory entity has been edited. <br><br> As you can see you are adding a Lecture to the student that is totally new to Student and it will not be overwritten since its EntityKey is different than the ones that coming from database as per your <em>LoadProperty()</em> call. <br><br> One solution would be to just simply clear all the Lectures from your student object just before <em>LoadProperty()</em>:</p> <pre><code>public void CancelChanges() { _context.Refresh(RefreshMode.StoreWins, this); this.Lectures.Clear(); _context.LoadProperty(this, (o) => o.Lectures, MergeOption.OverwriteChanges); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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