sunpengfei
2025-11-20 fb245f04af0c848128da7d14c61694736b4afde7
ApiTools.Core/Utils/DbUtils/DbUtils.cs
@@ -10,6 +10,7 @@
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
@@ -604,7 +605,12 @@
                            ? p.IsModified
                            : true)
                        .ToDictionary(p => p.Metadata.Name, p => p.OriginalValue));
                Db.GetRepository<DbAuditLog, LogDbContextLocator>().InsertNow(log);
                // 创建独立作用域
                using (var scope = App.GetRequiredService<IServiceScopeFactory>().CreateScope())
                {
                    var rep = scope.ServiceProvider.GetRequiredService<IRepository<DbAuditLog, LogDbContextLocator>>();
                    rep.InsertNow(log);
                }
            }
        }
    }