Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm not sure if this can be considered a Bug. What seems to happen is that the way you manipulate the LastModified property does not trigger INotifyPropertyChanged and thus the changes do not get populated to your Database.</p> <p>To prove it use: </p> <pre><code> order2.Name = "modified order2"; ((IObjectContextAdapter)context).ObjectContext.ObjectStateManager.GetObjectStateEntry(order2).SetModifiedProperty("LastModified"); </code></pre> <p>To utilize this knowledge in your SavingChangesHandler:</p> <pre><code>private void SavingChangesHandler(object sender, EventArgs e) { DateTimeOffset now = DateTimeOffset.Now; foreach (DbEntityEntry entry in ChangeTracker.Entries() .Where(entity =&gt; entity.State == EntityState.Added || entity.State == EntityState.Modified)) { SetModifiedDate(now, entry); if (entry.State == EntityState.Modified) { ((IObjectContextAdapter) this).ObjectContext.ObjectStateManager.GetObjectStateEntry(entry.Entity).SetModifiedProperty("LastModified"); } } } </code></pre> <p><strong>Edit:</strong></p> <p>I looked into this a little more and you are correct. For some reason MS decided to not fire PropertyChanged events when using PropertyInfo.SetValue anymore. Only one way to find out if this is a bug or a design decision: File a bug report / Post to msdn Forums.</p> <p>Though changing the property directly via CurrentValue seems to work fine:</p> <pre><code>private static void SetModifiedDate(DateTimeOffset now, DbEntityEntry modifiedEntity) { if (modifiedEntity.Entity == null) { return; } modifiedEntity.Property("LastModified").CurrentValue = now; } </code></pre>
    singulars
    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