From 35a7bb7b00e48ae5b335acff878dba9e9b220963 Mon Sep 17 00:00:00 2001 From: Reber Informatik GmbH Date: Tue, 25 Jul 2017 13:47:29 +0200 Subject: [PATCH] Fix formatting old-values when modifying entities FormatValue seems to work only on NewValue, as in this case the passed object entity is a POCO. Otherwise the passed entity seems to be a proxy, which has a different type. Only tested with EF6, EFCORE needs rework (?). --- .../AuditConfiguration/FormatValue.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/shared/Z.EF.Plus.Audit.Shared/AuditConfiguration/FormatValue.cs b/src/shared/Z.EF.Plus.Audit.Shared/AuditConfiguration/FormatValue.cs index 5c8933a2..afa715f4 100644 --- a/src/shared/Z.EF.Plus.Audit.Shared/AuditConfiguration/FormatValue.cs +++ b/src/shared/Z.EF.Plus.Audit.Shared/AuditConfiguration/FormatValue.cs @@ -38,7 +38,11 @@ public string FormatValue(object entity, string propertyName, object currentValu { if (EntityValueFormatters.Count > 0) { +#if EF5 || EF6 + var type = ObjectContext.GetObjectType(entity.GetType()); +#elif EFCORE var type = entity.GetType(); +#endif var key = string.Concat(type.FullName, ";", propertyName); Func formatter; @@ -69,4 +73,4 @@ public string FormatValue(object entity, string propertyName, object currentValu return currentValue != null && currentValue != DBNull.Value ? currentValue.ToString() : null; } } -} \ No newline at end of file +}