lijin
2025-11-21 0f9263238c5760267db714bb9fb6f4b86e202b22
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);
                }
            }
        }
    }