- 优化 主键 Guid 自动赋值的优先级,低于 Aop.AuditValue 事件(实现自定义 Guid 值);#274

This commit is contained in:
28810 2020-04-14 16:37:30 +08:00
parent f8fa15054c
commit 9ad454376e

View File

@ -139,6 +139,17 @@ namespace FreeSql.Internal.CommonProvider
foreach (var col in table.Columns.Values) foreach (var col in table.Columns.Values)
{ {
object val = col.GetMapValue(data); object val = col.GetMapValue(data);
if (orm.Aop.AuditValueHandler != null)
{
var auditArgs = new Aop.AuditValueEventArgs(Aop.AuditValueType.Insert, col, table.Properties[col.CsName], val);
orm.Aop.AuditValueHandler(sender, auditArgs);
if (auditArgs.IsChanged)
{
col.SetMapValue(data, val = auditArgs.Value);
if (changedDict != null && changedDict.ContainsKey(col.Attribute.Name) == false)
changedDict.Add(col.Attribute.Name, true);
}
}
if (col.Attribute.IsPrimary) if (col.Attribute.IsPrimary)
{ {
if (col.Attribute.MapType.NullableTypeOrThis() == typeof(Guid) && (val == null || (Guid)val == Guid.Empty)) if (col.Attribute.MapType.NullableTypeOrThis() == typeof(Guid) && (val == null || (Guid)val == Guid.Empty))
@ -153,17 +164,6 @@ namespace FreeSql.Internal.CommonProvider
} }
} }
} }
if (orm.Aop.AuditValueHandler != null)
{
var auditArgs = new Aop.AuditValueEventArgs(Aop.AuditValueType.Insert, col, table.Properties[col.CsName], val);
orm.Aop.AuditValueHandler(sender, auditArgs);
if (auditArgs.IsChanged)
{
col.SetMapValue(data, val = auditArgs.Value);
if (changedDict != null && changedDict.ContainsKey(col.Attribute.Name) == false)
changedDict.Add(col.Attribute.Name, true);
}
}
} }
} }