Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to find out if an Entity Framework object has changed?
    primarykey
    data
    text
    <p>I've an object which is called <code>Uczestnik</code> which just got saved to database </p> <pre><code>var konsultant = uczestnik.Konsultanci; uczestnik.Konsultanci = null; // null attached object and reuse it's ID later on for SAVE purposes uczestnik.KonsultantNazwa = konsultant.KonsultantNazwa; uczestnik.Szkolenie = null; // null attached object and reuse it's ID later on for SAVE purposes uczestnik.SzkolenieID = szkolenie.SzkolenieID; context.SzkolenieUczestnicies.AddObject(uczestnik); context.SaveChanges(); context.Detach(uczestnik); // detatch to prevent Context problems uczestnik.Szkolenie = szkolenie;// reassign for use in ObjectListView uczestnik.Konsultanci = konsultant; // reassign for use in ObjectListView </code></pre> <p>After it's saved it's back into ObjectListView where user decided to change some value and the value was changed (one value from multiple to be exact). If I check value's entity state it's in Unchanged state so calling .Attach and .SaveChanges() won't do anything. I can use <code>ChangeObjectState</code> but if there's nothing changed then there's no sense to do so.</p> <pre><code>context.SzkolenieUczestnicies.Attach(uczestnik); //context.ObjectStateManager.ChangeObjectState(uczestnik, EntityState.Modified); context.SaveChanges(); </code></pre> <p>How can I detect the change and prevent unnecessary traffic (I can imagine situation where nothing is changed in the object that holds files 5mb big) so <code>resaving</code> it makes no sense. Unless Entity is smart enough to detect that only one field was changed from 15 and change only that field? </p>
    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.
 

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