Upgraded audit engine to support EFCore's has conversion implemenation
This commit is contained in:
parent
e9616b18ee
commit
a3531e9a3e
@ -69,9 +69,18 @@ public class AuditEngineCore
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var currentValue = property.CurrentValue == null ? null : Convert.ChangeType(property.CurrentValue, property.CurrentValue!.GetType());
|
// Value converter + comparer
|
||||||
var oldValue = property.OriginalValue == null ? null : Convert.ChangeType(property.OriginalValue, property.OriginalValue!.GetType());
|
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 =
|
var isSoftDelete =
|
||||||
propertyInfo.CustomAttributes.SingleOrDefault(x =>
|
propertyInfo.CustomAttributes.SingleOrDefault(x =>
|
||||||
x.AttributeType == typeof(AuditSoftDeleteAttribute));
|
x.AttributeType == typeof(AuditSoftDeleteAttribute));
|
||||||
@ -96,9 +105,11 @@ public class AuditEngineCore
|
|||||||
var currentDisplayName = GetNewName(property) ?? GetEnumAsString(currentValue);
|
var currentDisplayName = GetNewName(property) ?? GetEnumAsString(currentValue);
|
||||||
var oldDisplayName = GetOldName(property) ?? GetEnumAsString(oldValue);
|
var oldDisplayName = GetOldName(property) ?? GetEnumAsString(oldValue);
|
||||||
|
|
||||||
var valuesMatch = (currentValue == null && oldValue == null) ||
|
// Compare using EF’s own comparer if available
|
||||||
(currentValue != null && currentValue.Equals(oldValue));
|
var valuesMatch = comparer != null
|
||||||
|
? comparer.Equals(currentClr, oldClr)
|
||||||
|
: Equals(currentValue, oldValue);
|
||||||
|
|
||||||
if (isRedacted)
|
if (isRedacted)
|
||||||
{
|
{
|
||||||
const string redacted = "<Redacted>";
|
const string redacted = "<Redacted>";
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user