ConfigureExternalServices执行两次 返回
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; }
}
还有我这么设置字段名,跟实体能映射起来吗?
热忱回答(14)
-
fate sta VIP02024/6/11
每个库的事件是独立的,所以会走2次
0 回复 -
fate sta VIP02024/6/11
第二个问题你先自测,有问题在发问,看着是没有问题
0 回复 -
乔一乔 VIP02024/6/11
@fate sta:我只给“core_db”设置了啊!
0 回复 -
fate sta VIP02024/6/11
@乔一乔: 这个是按字段来的 ,每个表的每个字段都会进来
0 回复 -
fate sta VIP02024/6/11
肯定会进多次,同一个字段不会进2次
0 回复 -
fate sta VIP02024/6/11
如果还有问题,提供完整DEMO
0 回复 -
fate sta VIP02024/6/11
删掉OBJ和BIN打包上传
0 回复 -
乔一乔 VIP02024/6/120 回复
-
fate sta VIP02024/6/12
你的实体已经有F了,在执行一次,不就2个FF?
结果是对的
0 回复 -
乔一乔 VIP02024/6/12
@fate sta:我给你的DEMO代码是加的X
0 回复 -
乔一乔 VIP02024/6/120 回复
-
乔一乔 VIP02024/6/22
顶!!!
0 回复 -
fate sta VIP02024/6/22
@乔一乔:
SqlSugarCore 5.1.4.159-preview25
已修复,过五分钟后勾一下预览 安装
0 回复 -
乔一乔 VIP02024/7/5
@fate sta:给你点个赞,祝sqlsugar越来越好!
0 回复