diff --git a/AutoHistory.sln b/AutoHistory.sln index ec1eaaf..d58c243 100644 --- a/AutoHistory.sln +++ b/AutoHistory.sln @@ -19,7 +19,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{1C12ACF7-CF58-460C-8EF3-2349D8E62AC1}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AspNetCore5.0.MVC.EF.Blogs", "samples\AspNetCore5.0.MVC.EF.Blogs\AspNetCore5.0.MVC.EF.Blogs.csproj", "{01180CD5-4F4E-4C51-9478-00090C03FE73}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AspNetCore.MVC.EF.Blogs", "samples\AspNetCore.MVC.EF.Blogs\AspNetCore.MVC.EF.Blogs.csproj", "{01180CD5-4F4E-4C51-9478-00090C03FE73}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/NuGet.config b/NuGet.config index 4e11f1b..5ede7dd 100644 --- a/NuGet.config +++ b/NuGet.config @@ -1,10 +1,12 @@ - - - - - - - - - - + + + + diff --git a/src/Microsoft.EntityFrameworkCore.AutoHistory/Extensions/DbContextExtensions.cs b/src/Microsoft.EntityFrameworkCore.AutoHistory/Extensions/DbContextExtensions.cs index 9f7b1ec..0a86b54 100644 --- a/src/Microsoft.EntityFrameworkCore.AutoHistory/Extensions/DbContextExtensions.cs +++ b/src/Microsoft.EntityFrameworkCore.AutoHistory/Extensions/DbContextExtensions.cs @@ -135,12 +135,12 @@ internal static TAutoHistory AddedHistory( var properties = GetPropertiesWithoutExcluded(entry); - dynamic json = new System.Dynamic.ExpandoObject(); + Dictionary json = new(); foreach (var prop in properties) { - ((IDictionary)json)[prop.Metadata.Name] = prop.OriginalValue != null ? - prop.OriginalValue - : null; + json[prop.Metadata.Name] = prop.OriginalValue != null ? + prop.OriginalValue + : null; } var history = createHistoryFactory(); history.TableName = entry.Metadata.GetTableName(); @@ -169,7 +169,7 @@ private static string PrimaryKey(this EntityEntry entry) private static void WriteHistoryAddedState(AutoHistory history, IEnumerable properties) { - dynamic json = new System.Dynamic.ExpandoObject(); + Dictionary json = new(); foreach (var prop in properties) { @@ -177,7 +177,7 @@ private static void WriteHistoryAddedState(AutoHistory history, IEnumerable)json)[prop.Metadata.Name] = prop.CurrentValue; + json[prop.Metadata.Name] = prop.CurrentValue; } // REVIEW: what's the best way to set the RowId? @@ -188,9 +188,9 @@ private static void WriteHistoryAddedState(AutoHistory history, IEnumerable properties) { - dynamic json = new System.Dynamic.ExpandoObject(); - dynamic bef = new System.Dynamic.ExpandoObject(); - dynamic aft = new System.Dynamic.ExpandoObject(); + Dictionary json = new(); + Dictionary bef = new(); + Dictionary aft = new(); PropertyValues databaseValues = null; foreach (var prop in properties) @@ -201,26 +201,26 @@ private static void WriteHistoryModifiedState(AutoHistory history, EntityEntry e { if (!prop.OriginalValue.Equals(prop.CurrentValue)) { - ((IDictionary)bef)[prop.Metadata.Name] = prop.OriginalValue; + bef[prop.Metadata.Name] = prop.OriginalValue; } else { databaseValues ??= entry.GetDatabaseValues(); var originalValue = databaseValues.GetValue(prop.Metadata.Name); - ((IDictionary)bef)[prop.Metadata.Name] = originalValue; + bef[prop.Metadata.Name] = originalValue; } } else { - ((IDictionary)bef)[prop.Metadata.Name] = null; + bef[prop.Metadata.Name] = null; } - ((IDictionary)aft)[prop.Metadata.Name] = prop.CurrentValue; + aft[prop.Metadata.Name] = prop.CurrentValue; } } - ((IDictionary)json)["before"] = bef; - ((IDictionary)json)["after"] = aft; + json["before"] = bef; + json["after"] = aft; history.RowId = entry.PrimaryKey(); history.Kind = EntityState.Modified; @@ -229,11 +229,11 @@ private static void WriteHistoryModifiedState(AutoHistory history, EntityEntry e private static void WriteHistoryDeletedState(AutoHistory history, EntityEntry entry, IEnumerable properties) { - dynamic json = new System.Dynamic.ExpandoObject(); + Dictionary json = new(); foreach (var prop in properties) { - ((IDictionary)json)[prop.Metadata.Name] = prop.OriginalValue; + json[prop.Metadata.Name] = prop.OriginalValue; } history.RowId = entry.PrimaryKey(); history.Kind = EntityState.Deleted;