ConfigureExternalServices执行两次 返回

SqlSugar 处理完成
14 460

public static void AddSqlsugarSetup(this IServiceCollection services)

{

    var coreDBConfig = new ConnectionConfig

    {

        ConfigId = "core_db",

        DbType = DbType.SqlServer,

        ConnectionString = AppSettings.CoreDBConnection,

        IsAutoCloseConnection = true,

        ConfigureExternalServices = new ConfigureExternalServices()

        {

            EntityService = (propertyInfo, columnInfo) =>

            {

                columnInfo.DbColumnName = $"F{columnInfo.DbColumnName}";

            }

        }

    };


    var designDBConfig = new ConnectionConfig

    {

        ConfigId = "design_db",

        DbType = DbType.SqlServer,

        ConnectionString = AppSettings.DesignDBConnection,

        IsAutoCloseConnection = true,

    };


    // 文档地址:https://www.donet5.com/Home/Doc?typeId=1204

    void configAction(SqlSugarClient db)

    {

        // 打印SQL语句

        db.Aop.OnLogExecuting = (sql, parameters) =>

        {

            Console.WriteLine(UtilMethods.GetSqlString(db.CurrentConnectionConfig.DbType, sql, parameters));

        };

    }


    SqlSugarScope sqlSugar = new([coreDBConfig,designDBConfig], configAction);


    sqlSugar.GetConnectionScope("core_db").DbMaintenance.CreateDatabase();

    sqlSugar.GetConnectionScope("core_db").CodeFirst.SetStringDefaultLength(200).InitTables(typeof(User));

    sqlSugar.GetConnectionScope("design_db").DbMaintenance.CreateDatabase();

    sqlSugar.GetConnectionScope("design_db").CodeFirst.SetStringDefaultLength(200).InitTables(typeof(Demo));


    services.AddSingleton<ISqlSugarClient>(s => sqlSugar);


}



[TenantAttribute("core_db"), SugarTable("t_sys_user")]

public class User

{

    [SugarColumn(IsPrimaryKey = true, IsIdentity = true)]

    public int Id { get; set; }


    public required string AccountName { get; set; }


    public required string Password { get; set; }


    public required string Name { get; set; }


    public required string Avatar { get; set; }


    public required string Email { get; set; }


    public required string PhoneNumber { get; set; }

}



1718104458821.png



还有我这么设置字段名,跟实体能映射起来吗?

热忱回答14