Skip to content

Commit 3ce1043

Browse files
committed
- 优化 AggregateRoot MapEntityValue 支持将实体映射到字典;
- 修复 AggregateRoot CompareEntityValue 错误;
1 parent 12e0711 commit 3ce1043

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

Extensions/FreeSql.Extensions.AggregateRoot/AggregateRootRepository/AggregateRootRepository.cs

+6-7
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,12 @@ public Dictionary<string, object[]> CompareState(TEntity newdata)
9999
if (string.IsNullOrEmpty(key)) throw new Exception(DbContextErrorStrings.Incomparable_PrimaryKey_NotSet(Orm.GetEntityString(EntityType, newdata)));
100100
if (_states.TryGetValue(key, out var oldState) == false || oldState == null) throw new Exception($"不可对比,数据未被跟踪:{Orm.GetEntityString(EntityType, newdata)}");
101101
AggregateRootTrackingChangeInfo tracking = new AggregateRootTrackingChangeInfo();
102-
AggregateRootUtils.CompareEntityValue(_boundaryName, Orm, EntityType, oldState, newdata, null, tracking);
103-
return new Dictionary<string, object[]>
104-
{
105-
["Insert"] = tracking.InsertLog.Select(a => new object[] { a.Item1, a.Item2 }).ToArray(),
106-
["Delete"] = tracking.DeleteLog.Select(a => new object[] { a.Item1, a.Item2 }).ToArray(),
107-
["Update"] = tracking.UpdateLog.Select(a => new object[] { a.Item1, a.Item2, a.Item3, a.Item4 }).ToArray(),
108-
};
102+
AggregateRootUtils.CompareEntityValue(_boundaryName, Orm, EntityType, oldState.Value, newdata, null, tracking);
103+
var result = new Dictionary<string, object[]>();
104+
if (tracking.InsertLog.Any()) result.Add("Insert", tracking.InsertLog.Select(a => new object[] { a.Item1, a.Item2 }).ToArray());
105+
if (tracking.DeleteLog.Any()) result.Add("Delete", tracking.DeleteLog.Select(a => new object[] { a.Item1, a.Item2 }).ToArray());
106+
if (tracking.UpdateLog.Any()) result.Add("Update", tracking.UpdateLog.Select(a => new object[] { a.Item1, a.Item2, a.Item3, a.Item4 }).ToArray());
107+
return result;
109108
}
110109
public void FlushState()
111110
{

0 commit comments

Comments
 (0)