Skip to content

Commit

Permalink
- 优化 InsertOrUpdate AsType 使用错误的友好提示;
Browse files Browse the repository at this point in the history
  • Loading branch information
28810 authored and 28810 committed Aug 25, 2020
1 parent a9f9832 commit a634192
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 33 deletions.
16 changes: 0 additions & 16 deletions FreeSql.DbContext/FreeSql.DbContext.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 2 additions & 17 deletions FreeSql/Internal/CommonProvider/InsertOrUpdateProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,30 +72,15 @@ public IInsertOrUpdate<T1> UpdateColumns(string[] columns)
public static void AuditDataValue(object sender, IEnumerable<T1> data, IFreeSql orm, TableInfo table, Dictionary<string, bool> changedDict)
{
if (data?.Any() != true) return;
if (orm.Aop.AuditValueHandler == null) return;
foreach (var d in data)
{
if (d == null) continue;
foreach (var col in table.Columns.Values)
{
object val = col.GetValue(d);
var auditArgs = new Aop.AuditValueEventArgs(Aop.AuditValueType.InsertOrUpdate, col, table.Properties[col.CsName], val);
orm.Aop.AuditValueHandler(sender, auditArgs);
if (auditArgs.ValueIsChanged)
{
col.SetValue(d, val = auditArgs.Value);
if (changedDict != null && changedDict.ContainsKey(col.Attribute.Name) == false)
changedDict.Add(col.Attribute.Name, true);
}
}
}
AuditDataValue(sender, d, orm, table, changedDict);
}
public static void AuditDataValue(object sender, T1 data, IFreeSql orm, TableInfo table, Dictionary<string, bool> changedDict)
{
if (orm.Aop.AuditValueHandler == null) return;
if (data == null) return;
if (typeof(T1) == typeof(object) && new[] { table.Type, table.TypeLazy }.Contains(data.GetType()) == false)
throw new Exception($"操作的数据类型({data.GetType().DisplayCsharp()}) 与 AsType({table.Type.DisplayCsharp()}) 不一致,请检查。");
if (orm.Aop.AuditValueHandler == null) return;
foreach (var col in table.Columns.Values)
{
object val = col.GetValue(data);
Expand Down

0 comments on commit a634192

Please sign in to comment.