mirror of
				https://github.com/nsnail/FreeSql.git
				synced 2025-11-04 01:05:27 +08:00 
			
		
		
		
	- 增加 DbContextOptions.AuditValue 基于 Ioc Scoped 审计值;
This commit is contained in:
		@@ -263,7 +263,28 @@ namespace FreeSql
 | 
			
		||||
                    }));
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            var updateLogDict = tracking.UpdateLog.GroupBy(a => a.Item1).ToDictionary(a => a.Key, a => tracking.UpdateLog.Where(b => b.Item1 == a.Key).Select(b => new
 | 
			
		||||
            if (_repository.DbContextOptions.AuditValueHandler != null)
 | 
			
		||||
            {
 | 
			
		||||
                foreach (var log in tracking.UpdateLog)
 | 
			
		||||
                {
 | 
			
		||||
                    var table = Orm.CodeFirst.GetTableByEntity(log.Item1);
 | 
			
		||||
                    _repository.DbContextOptions.AuditValueHandler(this, new DbContextAuditValueEventArgs(Aop.AuditValueType.Update, log.Item1, log.Item3));
 | 
			
		||||
                    log.Item4.Clear();
 | 
			
		||||
                    foreach (var col in table.ColumnsByCs.Values)
 | 
			
		||||
                    {
 | 
			
		||||
                        if (table.ColumnsByCsIgnore.ContainsKey(col.CsName)) continue;
 | 
			
		||||
                        if (table.ColumnsByCs.ContainsKey(col.CsName))
 | 
			
		||||
                        {
 | 
			
		||||
                            if (col.Attribute.IsVersion) continue;
 | 
			
		||||
                            var propvalBefore = table.GetPropertyValue(log.Item2, col.CsName);
 | 
			
		||||
                            var propvalAfter = table.GetPropertyValue(log.Item3, col.CsName);
 | 
			
		||||
                            if (AggregateRootUtils.CompareEntityPropertyValue(col.CsType, propvalBefore, propvalAfter) == false) log.Item4.Add(col.CsName);
 | 
			
		||||
                            continue;
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            var updateLogDict = tracking.UpdateLog.GroupBy(a => a.Item1).ToDictionary(a => a.Key, a => tracking.UpdateLog.Where(b => b.Item1 == a.Key && b.Item4.Any()).Select(b => new
 | 
			
		||||
            {
 | 
			
		||||
                BeforeObject = b.Item2,
 | 
			
		||||
                AfterObject = b.Item3,
 | 
			
		||||
 
 | 
			
		||||
@@ -314,7 +314,28 @@ namespace FreeSql
 | 
			
		||||
                    }));
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            var updateLogDict = tracking.UpdateLog.GroupBy(a => a.Item1).ToDictionary(a => a.Key, a => tracking.UpdateLog.Where(b => b.Item1 == a.Key).Select(b => new
 | 
			
		||||
            if (_repository.DbContextOptions.AuditValueHandler != null)
 | 
			
		||||
            {
 | 
			
		||||
                foreach (var log in tracking.UpdateLog)
 | 
			
		||||
                {
 | 
			
		||||
                    var table = Orm.CodeFirst.GetTableByEntity(log.Item1);
 | 
			
		||||
                    _repository.DbContextOptions.AuditValueHandler(this, new DbContextAuditValueEventArgs(Aop.AuditValueType.Update, log.Item1, log.Item3));
 | 
			
		||||
                    log.Item4.Clear();
 | 
			
		||||
                    foreach (var col in table.ColumnsByCs.Values)
 | 
			
		||||
                    {
 | 
			
		||||
                        if (table.ColumnsByCsIgnore.ContainsKey(col.CsName)) continue;
 | 
			
		||||
                        if (table.ColumnsByCs.ContainsKey(col.CsName))
 | 
			
		||||
                        {
 | 
			
		||||
                            if (col.Attribute.IsVersion) continue;
 | 
			
		||||
                            var propvalBefore = table.GetPropertyValue(log.Item2, col.CsName);
 | 
			
		||||
                            var propvalAfter = table.GetPropertyValue(log.Item3, col.CsName);
 | 
			
		||||
                            if (AggregateRootUtils.CompareEntityPropertyValue(col.CsType, propvalBefore, propvalAfter) == false) log.Item4.Add(col.CsName);
 | 
			
		||||
                            continue;
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            var updateLogDict = tracking.UpdateLog.GroupBy(a => a.Item1).ToDictionary(a => a.Key, a => tracking.UpdateLog.Where(b => b.Item1 == a.Key && b.Item4.Any()).Select(b => new
 | 
			
		||||
            {
 | 
			
		||||
                BeforeObject = b.Item2,
 | 
			
		||||
                AfterObject = b.Item3,
 | 
			
		||||
 
 | 
			
		||||
@@ -23,12 +23,12 @@
 | 
			
		||||
	</PropertyGroup>
 | 
			
		||||
 | 
			
		||||
	<ItemGroup>
 | 
			
		||||
		<None Include="../../readme.md" Pack="true" PackagePath="\"/>
 | 
			
		||||
		<None Include="../../readme.md" Pack="true" PackagePath="\" />
 | 
			
		||||
		<None Include="../../logo.png" Pack="true" PackagePath="\" />
 | 
			
		||||
	</ItemGroup>
 | 
			
		||||
 | 
			
		||||
	<ItemGroup>
 | 
			
		||||
		<PackageReference Include="FreeSql.DbContext" Version="3.2.811-preview20240125" />
 | 
			
		||||
	  <ProjectReference Include="..\..\FreeSql.DbContext\FreeSql.DbContext.csproj" />
 | 
			
		||||
	</ItemGroup>
 | 
			
		||||
 | 
			
		||||
	<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|netstandard2.0|AnyCPU'">
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user