Skip to content

Commit 6e64d8f

Browse files
author
zzzprojects
committed
Update to v1.4.39
Update to v1.4.39
1 parent c32359a commit 6e64d8f

File tree

111 files changed

+3655
-710
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+3655
-710
lines changed

src/Z.EntityFramework.Plus.EF5.NET40/Audit/Audit/AuditEntityModified.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public static void AuditEntityModified(Audit audit, AuditEntry entry, EntityEntr
115115
entry.Parent.Configuration.AuditEntryPropertyFactory(new AuditEntryPropertyArgs(entry, objectStateEntry, propertyEntry.Name, property.OriginalValue, property.CurrentValue)) :
116116
new AuditEntryProperty();
117117

118-
auditEntryProperty.Build(entry, propertyEntry.Name, property.OriginalValue, propertyEntry);
118+
auditEntryProperty.Build(entry, propertyEntry.Name, property.OriginalValue, property);
119119
entry.Properties.Add(auditEntryProperty);
120120
}
121121
}

src/Z.EntityFramework.Plus.EF5.NET40/Audit/Audit/PostSaveChanges.cs

Lines changed: 72 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ public static void PostSaveChanges(Audit audit)
5858
property.NewValue = currentValue;
5959
}
6060
}
61+
#elif EFCORE
62+
foreach (var property in entry.Properties)
63+
{
64+
if (!property.IsValueSet)
65+
{
66+
var currentValue = property.PropertyEntry.CurrentValue;
67+
property.NewValue = currentValue;
68+
}
69+
}
6170
#endif
6271
break;
6372
case AuditEntryState.RelationshipAdded:
@@ -67,75 +76,75 @@ public static void PostSaveChanges(Audit audit)
6776
break;
6877
}
6978
}
70-
// foreach (var entry in audit.Entries)
71-
// {
72-
// if (entry.DelayedKey != null)
73-
// {
74-
//#if EF5 || EF6
75-
// var objectStateEntry = entry.DelayedKey as ObjectStateEntry;
76-
//#elif EFCORE
77-
// var objectStateEntry = entry.DelayedKey as EntityEntry;
78-
//#endif
79-
// if (objectStateEntry != null)
80-
// {
81-
//#if EF5 || EF6
82-
// if (objectStateEntry.IsRelationship)
83-
// {
84-
// var values = objectStateEntry.CurrentValues;
85-
// var leftKeys = (EntityKey) values.GetValue(0);
86-
// var rightKeys = (EntityKey) values.GetValue(1);
87-
// var leftRelationName = values.GetName(0);
88-
// var rightRelationName = values.GetName(1);
79+
// foreach (var entry in audit.Entries)
80+
// {
81+
// if (entry.DelayedKey != null)
82+
// {
83+
//#if EF5 || EF6
84+
// var objectStateEntry = entry.DelayedKey as ObjectStateEntry;
85+
//#elif EFCORE
86+
// var objectStateEntry = entry.DelayedKey as EntityEntry;
87+
//#endif
88+
// if (objectStateEntry != null)
89+
// {
90+
//#if EF5 || EF6
91+
// if (objectStateEntry.IsRelationship)
92+
// {
93+
// var values = objectStateEntry.CurrentValues;
94+
// var leftKeys = (EntityKey) values.GetValue(0);
95+
// var rightKeys = (EntityKey) values.GetValue(1);
96+
// var leftRelationName = values.GetName(0);
97+
// var rightRelationName = values.GetName(1);
8998

90-
// foreach (var keyValue in leftKeys.EntityKeyValues)
91-
// {
92-
// var auditEntryProperty = audit.Configuration.AuditEntryPropertyFactory != null ?
93-
// audit.Configuration.AuditEntryPropertyFactory(new AuditEntryPropertyArgs(entry, objectStateEntry, leftRelationName, keyValue.Key, null, keyValue.Value)) :
94-
// new AuditEntryProperty();
99+
// foreach (var keyValue in leftKeys.EntityKeyValues)
100+
// {
101+
// var auditEntryProperty = audit.Configuration.AuditEntryPropertyFactory != null ?
102+
// audit.Configuration.AuditEntryPropertyFactory(new AuditEntryPropertyArgs(entry, objectStateEntry, leftRelationName, keyValue.Key, null, keyValue.Value)) :
103+
// new AuditEntryProperty();
95104

96-
// auditEntryProperty.Build(entry, leftRelationName, keyValue.Key, null, keyValue.Value);
97-
// entry.Properties.Add(auditEntryProperty);
98-
// }
105+
// auditEntryProperty.Build(entry, leftRelationName, keyValue.Key, null, keyValue.Value);
106+
// entry.Properties.Add(auditEntryProperty);
107+
// }
99108

100-
// foreach (var keyValue in rightKeys.EntityKeyValues)
101-
// {
102-
// var auditEntryProperty = audit.Configuration.AuditEntryPropertyFactory != null ?
103-
// audit.Configuration.AuditEntryPropertyFactory(new AuditEntryPropertyArgs(entry, objectStateEntry, rightRelationName, keyValue.Key, null, keyValue.Value)) :
104-
// new AuditEntryProperty();
109+
// foreach (var keyValue in rightKeys.EntityKeyValues)
110+
// {
111+
// var auditEntryProperty = audit.Configuration.AuditEntryPropertyFactory != null ?
112+
// audit.Configuration.AuditEntryPropertyFactory(new AuditEntryPropertyArgs(entry, objectStateEntry, rightRelationName, keyValue.Key, null, keyValue.Value)) :
113+
// new AuditEntryProperty();
105114

106-
// auditEntryProperty.Build(entry, rightRelationName, keyValue.Key, null, keyValue.Value);
107-
// entry.Properties.Add(auditEntryProperty);
108-
// }
109-
// }
110-
// else
111-
// {
112-
// foreach (var keyValue in objectStateEntry.EntityKey.EntityKeyValues)
113-
// {
114-
// var property = entry.Properties.FirstOrDefault(x => x.InternalPropertyName == keyValue.Key);
115+
// auditEntryProperty.Build(entry, rightRelationName, keyValue.Key, null, keyValue.Value);
116+
// entry.Properties.Add(auditEntryProperty);
117+
// }
118+
// }
119+
// else
120+
// {
121+
// foreach (var keyValue in objectStateEntry.EntityKey.EntityKeyValues)
122+
// {
123+
// var property = entry.Properties.FirstOrDefault(x => x.InternalPropertyName == keyValue.Key);
115124

116-
// // ENSURE the property is audited
117-
// if (property != null)
118-
// {
119-
// property.NewValue = keyValue.Value;
120-
// }
121-
// }
122-
// }
123-
// }
124-
//#elif EFCORE
125-
// foreach (var keyValue in objectStateEntry.Metadata.GetKeys())
126-
// {
127-
// var key = objectStateEntry.Property(keyValue.Properties[0].Name);
128-
// var property = entry.Properties.FirstOrDefault(x => x.InternalPropertyName == keyValue.Properties[0].Name);
125+
// // ENSURE the property is audited
126+
// if (property != null)
127+
// {
128+
// property.NewValue = keyValue.Value;
129+
// }
130+
// }
131+
// }
132+
// }
133+
//#elif EFCORE
134+
// foreach (var keyValue in objectStateEntry.Metadata.GetKeys())
135+
// {
136+
// var key = objectStateEntry.Property(keyValue.Properties[0].Name);
137+
// var property = entry.Properties.FirstOrDefault(x => x.InternalPropertyName == keyValue.Properties[0].Name);
129138

130-
// // ENSURE the property is audited
131-
// if (property != null)
132-
// {
133-
// property.NewValue = key.CurrentValue;
134-
// }
135-
// }
136-
// }
137-
//#endif
138-
// }
139+
// // ENSURE the property is audited
140+
// if (property != null)
141+
// {
142+
// property.NewValue = key.CurrentValue;
143+
// }
144+
// }
145+
// }
146+
//#endif
147+
// }
139148
//}
140149
}
141150
}

src/Z.EntityFramework.Plus.EF5.NET40/Audit/AuditConfiguration/FormatValue.cs

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,41 +31,38 @@ public partial class AuditConfiguration
3131
/// <param name="propertyName">The property name.</param>
3232
/// <returns>The formatted value.</returns>
3333
#if EF5 || EF6
34-
public string FormatValue(ObjectStateEntry entry, string propertyName, object currentValue)
34+
public string FormatValue(object entity, string propertyName, object currentValue)
3535
#elif EFCORE
3636
public string FormatValue(EntityEntry entry, string propertyName, object currentValue)
3737
#endif
3838
{
3939
if (EntityValueFormatters.Count > 0)
4040
{
41-
if (entry.State != EntityState.Detached && entry.Entity != null)
42-
{
43-
var type = entry.Entity.GetType();
44-
var key = string.Concat(type.FullName, ";", propertyName);
45-
Func<object, object> formatter;
41+
var type = entity.GetType();
42+
var key = string.Concat(type.FullName, ";", propertyName);
43+
Func<object, object> formatter;
4644

47-
if (!ValueFormatterDictionary.TryGetValue(key, out formatter))
45+
if (!ValueFormatterDictionary.TryGetValue(key, out formatter))
46+
{
47+
if (EntityValueFormatters.Count > 0)
4848
{
49-
if (EntityValueFormatters.Count > 0)
49+
foreach (var formatProperty in EntityValueFormatters)
5050
{
51-
foreach (var formatProperty in EntityValueFormatters)
52-
{
53-
formatter = formatProperty(entry.Entity, propertyName);
51+
formatter = formatProperty(entity, propertyName);
5452

55-
if (formatter != null)
56-
{
57-
break;
58-
}
53+
if (formatter != null)
54+
{
55+
break;
5956
}
6057
}
61-
62-
ValueFormatterDictionary.TryAdd(key, formatter);
6358
}
6459

65-
if (formatter != null)
66-
{
67-
currentValue = formatter(currentValue);
68-
}
60+
ValueFormatterDictionary.TryAdd(key, formatter);
61+
}
62+
63+
if (formatter != null)
64+
{
65+
currentValue = formatter(currentValue);
6966
}
7067
}
7168

src/Z.EntityFramework.Plus.EF5.NET40/Audit/AuditEntry.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ public void Build(Audit parent, EntityEntry entry)
4646
Entry = entry;
4747
}
4848

49+
if (Entity == null)
50+
{
51+
Entity = Entry.Entity;
52+
}
53+
4954
if (Parent == null)
5055
{
5156
Parent = parent;
@@ -108,14 +113,24 @@ public void Build(Audit parent, EntityEntry entry)
108113
internal object DelayedKey;
109114
#endif
110115

116+
/// <summary>Gets or sets the object state entry.</summary>
117+
/// <value>The object state entry.</value>
118+
[NotMapped]
119+
#if EF5 || EF6
120+
public object Entity { get; set; }
121+
#elif EFCORE
122+
// EFCORE still have some issue with "NotMapped" attribute
123+
public object Entity;
124+
#endif
125+
111126
/// <summary>Gets or sets the object state entry.</summary>
112127
/// <value>The object state entry.</value>
113128
[NotMapped]
114129
#if EF5 || EF6
115130
public ObjectStateEntry Entry { get; set; }
116131
#elif EFCORE
117132
// EFCORE still have some issue with "NotMapped" attribute
118-
public EntityEntry Entry { get; set; }
133+
public EntityEntry Entry;
119134
#endif
120135

121136
/// <summary>Gets or sets the name of the entity set.</summary>

src/Z.EntityFramework.Plus.EF5.NET40/Audit/AuditEntryProperty.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ public void Build(AuditEntry parent, string relationName, string propertyName, o
176176
public object NewValue { get; set; }
177177
#elif EFCORE
178178
[NotMapped]
179-
public PropertyEntry PropertyEntry { get; set; }
179+
public PropertyEntry PropertyEntry;
180+
180181
// EFCORE still have some issue with "NotMapped" attribute
181182
public object NewValue;
182183
#endif
@@ -202,7 +203,7 @@ public string NewValueFormatted
202203

203204
if (Parent != null && Parent.Parent != null && Parent.State != AuditEntryState.EntityDeleted)
204205
{
205-
return Parent.Parent.CurrentOrDefaultConfiguration.FormatValue(Parent.Entry, PropertyName, currentValue);
206+
return Parent.Parent.CurrentOrDefaultConfiguration.FormatValue(Parent.Entity, PropertyName, currentValue);
206207
}
207208

208209
return currentValue != null && currentValue != DBNull.Value ? currentValue.ToString() : null;
@@ -237,7 +238,7 @@ public string OldValueFormatted
237238

238239
if (Parent != null && Parent.Parent != null && Parent.State != AuditEntryState.EntityAdded)
239240
{
240-
return Parent.Parent.CurrentOrDefaultConfiguration.FormatValue(Parent.Entry, PropertyName, currentValue);
241+
return Parent.Parent.CurrentOrDefaultConfiguration.FormatValue(Parent.Entity, PropertyName, currentValue);
241242
}
242243

243244
return currentValue != null && currentValue != DBNull.Value ? currentValue.ToString() : null;

0 commit comments

Comments
 (0)