Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AutoHistory.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 12 additions & 10 deletions NuGet.config
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<!-- <?xml version="1.0" encoding="utf-8"?> -->
<!-- <configuration> -->
<!-- <packageRestore> -->
<!-- <add key="automatic" value="False" /> -->
<!-- </packageRestore> -->
<!-- <packageSources> -->
<!-- <add key="AspNetCore" value="https://dotnet.myget.org/F/aspnetcore-ci-dev/api/v3/index.json" /> -->
<!-- <add key="NuGet" value="https://api.nuget.org/v3/index.json" /> -->
<!-- </packageSources> -->
<!-- </configuration> -->
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!--
<packageRestore>
<add key="automatic" value="False" />
</packageRestore>
<packageSources>
<add key="AspNetCore" value="https://dotnet.myget.org/F/aspnetcore-ci-dev/api/v3/index.json" />
<add key="NuGet" value="https://api.nuget.org/v3/index.json" />
</packageSources>
-->
</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,12 @@ internal static TAutoHistory AddedHistory<TAutoHistory>(

var properties = GetPropertiesWithoutExcluded(entry);

dynamic json = new System.Dynamic.ExpandoObject();
Dictionary<string, object> json = new();
foreach (var prop in properties)
{
((IDictionary<string, object>)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();
Expand Down Expand Up @@ -169,15 +169,15 @@ private static string PrimaryKey(this EntityEntry entry)

private static void WriteHistoryAddedState(AutoHistory history, IEnumerable<PropertyEntry> properties)
{
dynamic json = new System.Dynamic.ExpandoObject();
Dictionary<string, object> json = new();

foreach (var prop in properties)
{
if (prop.Metadata.IsKey() || prop.Metadata.IsForeignKey())
{
continue;
}
((IDictionary<String, Object>)json)[prop.Metadata.Name] = prop.CurrentValue;
json[prop.Metadata.Name] = prop.CurrentValue;
}

// REVIEW: what's the best way to set the RowId?
Expand All @@ -188,9 +188,9 @@ private static void WriteHistoryAddedState(AutoHistory history, IEnumerable<Prop

private static void WriteHistoryModifiedState(AutoHistory history, EntityEntry entry, IEnumerable<PropertyEntry> properties)
{
dynamic json = new System.Dynamic.ExpandoObject();
dynamic bef = new System.Dynamic.ExpandoObject();
dynamic aft = new System.Dynamic.ExpandoObject();
Dictionary<string, object> json = new();
Dictionary<string, object> bef = new();
Dictionary<string, object> aft = new();

PropertyValues databaseValues = null;
foreach (var prop in properties)
Expand All @@ -201,26 +201,26 @@ private static void WriteHistoryModifiedState(AutoHistory history, EntityEntry e
{
if (!prop.OriginalValue.Equals(prop.CurrentValue))
{
((IDictionary<String, Object>)bef)[prop.Metadata.Name] = prop.OriginalValue;
bef[prop.Metadata.Name] = prop.OriginalValue;
}
else
{
databaseValues ??= entry.GetDatabaseValues();
var originalValue = databaseValues.GetValue<object>(prop.Metadata.Name);
((IDictionary<String, Object>)bef)[prop.Metadata.Name] = originalValue;
bef[prop.Metadata.Name] = originalValue;
}
}
else
{
((IDictionary<String, Object>)bef)[prop.Metadata.Name] = null;
bef[prop.Metadata.Name] = null;
}

((IDictionary<String, Object>)aft)[prop.Metadata.Name] = prop.CurrentValue;
aft[prop.Metadata.Name] = prop.CurrentValue;
}
}

((IDictionary<String, Object>)json)["before"] = bef;
((IDictionary<String, Object>)json)["after"] = aft;
json["before"] = bef;
json["after"] = aft;

history.RowId = entry.PrimaryKey();
history.Kind = EntityState.Modified;
Expand All @@ -229,11 +229,11 @@ private static void WriteHistoryModifiedState(AutoHistory history, EntityEntry e

private static void WriteHistoryDeletedState(AutoHistory history, EntityEntry entry, IEnumerable<PropertyEntry> properties)
{
dynamic json = new System.Dynamic.ExpandoObject();
Dictionary<string, object> json = new();

foreach (var prop in properties)
{
((IDictionary<String, Object>)json)[prop.Metadata.Name] = prop.OriginalValue;
json[prop.Metadata.Name] = prop.OriginalValue;
}
history.RowId = entry.PrimaryKey();
history.Kind = EntityState.Deleted;
Expand Down