Upgraded audit engine to support EFCore's has conversion implemenation
This commit is contained in:
parent
e9616b18ee
commit
a3531e9a3e
@ -69,8 +69,17 @@ public class AuditEngineCore
|
||||
continue;
|
||||
}
|
||||
|
||||
var currentValue = property.CurrentValue == null ? null : Convert.ChangeType(property.CurrentValue, property.CurrentValue!.GetType());
|
||||
var oldValue = property.OriginalValue == null ? null : Convert.ChangeType(property.OriginalValue, property.OriginalValue!.GetType());
|
||||
// Value converter + comparer
|
||||
var converter = property.Metadata.GetValueConverter(); //todo need a unit test for when a value converter is present on the table.
|
||||
var comparer = property.Metadata.GetValueComparer();
|
||||
|
||||
// Raw CLR values
|
||||
var currentClr = property.CurrentValue;
|
||||
var oldClr = property.OriginalValue;
|
||||
|
||||
// Convert to provider (JSON for Tasks)
|
||||
var currentValue = converter?.ConvertToProvider(currentClr) ?? currentClr;
|
||||
var oldValue = converter?.ConvertToProvider(oldClr) ?? oldClr;
|
||||
|
||||
var isSoftDelete =
|
||||
propertyInfo.CustomAttributes.SingleOrDefault(x =>
|
||||
@ -96,8 +105,10 @@ public class AuditEngineCore
|
||||
var currentDisplayName = GetNewName(property) ?? GetEnumAsString(currentValue);
|
||||
var oldDisplayName = GetOldName(property) ?? GetEnumAsString(oldValue);
|
||||
|
||||
var valuesMatch = (currentValue == null && oldValue == null) ||
|
||||
(currentValue != null && currentValue.Equals(oldValue));
|
||||
// Compare using EF’s own comparer if available
|
||||
var valuesMatch = comparer != null
|
||||
? comparer.Equals(currentClr, oldClr)
|
||||
: Equals(currentValue, oldValue);
|
||||
|
||||
if (isRedacted)
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user