0

I had this working originally, however it seems it has stopped working. The value of originalValue and currentValue always seem to be the same.

Here's my code

Public Overrides Function SaveChanges() As Integer

    Dim modifiedEntities = ChangeTracker.Entries.ToList

    For Each ent As DbEntityEntry In modifiedEntities
        If ent.State = EntityState.Modified Then
            Dim type = ent.Entity.GetType.Name
            Dim primaryKey = GetPrimaryKeyValue(ent)

            Dim jo As New JObject
            For Each prop In ent.OriginalValues.PropertyNames
                Dim originalValue = ent.OriginalValues(prop).ToString
                Dim currentValue = ent.CurrentValues(prop).ToString
                If originalValue <> currentValue Then
                    jo.Add(New JProperty(prop, currentValue))
                End If
            Next
        End If
    Next

    Return MyBase.SaveChanges()

End Function

I know that nothing actually gets done with the JSON object, however when stepping through the code the originalValue is always the same as the currentValue if even the value has been updated.

Jacob Mason
  • 1,355
  • 5
  • 14
  • 28

1 Answers1

0

You may try this:
How to get original values of an entity in Entity Framework?

Dim originalValue = CType(context.ObjectStateManager.GetObjectStateEntry(ent).OriginalValues(prop), String)
Community
  • 1
  • 1
Gabor
  • 3,021
  • 1
  • 11
  • 20