修复.NET bool类型转换为pgSql int2

This commit is contained in:
wintel 2025-02-23 21:11:42 +08:00
parent 8608aea1e9
commit f6b7ba8b88
5 changed files with 100 additions and 7 deletions

View File

@ -79,6 +79,25 @@ namespace OpenAuth.App.Test
ConnectionString = connectionString,
IsAutoCloseConnection = true
});
if(dbType.Value != SqlSugar.DbType.PostgreSQL){
return sqlSugar;
}
// 配置bool类型转换为smallint
sqlSugar.Aop.OnExecutingChangeSql = (sql, parameters) =>
{
foreach (var param in parameters)
{
if (param.Value is bool boolValue)
{
param.DbType = System.Data.DbType.Int16;
// 将 bool 转换为 smallint
param.Value = boolValue ? (short)1 : (short)0;
}
}
// 返回修改后的 SQL 和参数
return new System.Collections.Generic.KeyValuePair<string, SugarParameter[]>(sql, parameters);
};
return sqlSugar;
});

View File

@ -104,13 +104,27 @@ namespace OpenAuth.IdentityServer
{
DbType = sugarDbtype.Value,
ConnectionString = connectionString,
IsAutoCloseConnection = true,
MoreSettings=new ConnMoreSettings() {
PgSqlIsAutoToLower = false,//增删查改支持驼峰表
PgSqlIsAutoToLowerCodeFirst = false, // 建表建驼峰表。5.1.3.30
IsAutoToUpper=false //禁用自动转成大写表
}
IsAutoCloseConnection = true
});
if(sugarDbtype.Value != SqlSugar.DbType.PostgreSQL){
return sqlSugar;
}
// 配置bool类型转换为smallint
sqlSugar.Aop.OnExecutingChangeSql = (sql, parameters) =>
{
foreach (var param in parameters)
{
if (param.Value is bool boolValue)
{
param.DbType = System.Data.DbType.Int16;
// 将 bool 转换为 smallint
param.Value = boolValue ? (short)1 : (short)0;
}
}
// 返回修改后的 SQL 和参数
return new System.Collections.Generic.KeyValuePair<string, SugarParameter[]>(sql, parameters);
};
return sqlSugar;
});

View File

@ -111,6 +111,26 @@ namespace OpenAuth.Mvc
ConnectionString = connectionString,
IsAutoCloseConnection = true
}, db => { db.Aop.OnLogExecuting = (sql, pars) => { logger.LogInformation(sql); }; });
if(dbType.Value != SqlSugar.DbType.PostgreSQL){
return sqlSugar;
}
// 配置bool类型转换为smallint
sqlSugar.Aop.OnExecutingChangeSql = (sql, parameters) =>
{
foreach (var param in parameters)
{
if (param.Value is bool boolValue)
{
param.DbType = System.Data.DbType.Int16;
// 将 bool 转换为 smallint
param.Value = boolValue ? (short)1 : (short)0;
}
}
// 返回修改后的 SQL 和参数
return new System.Collections.Generic.KeyValuePair<string, SugarParameter[]>(sql, parameters);
};
return sqlSugar;
});

View File

@ -85,6 +85,26 @@ namespace OpenAuth.Repository.Test
ConnectionString = connectionString,
IsAutoCloseConnection = true
});
if(dbType.Value != SqlSugar.DbType.PostgreSQL){
return sqlSugar;
}
// 配置bool类型转换为smallint
sqlSugar.Aop.OnExecutingChangeSql = (sql, parameters) =>
{
foreach (var param in parameters)
{
if (param.Value is bool boolValue)
{
param.DbType = System.Data.DbType.Int16;
// 将 bool 转换为 smallint
param.Value = boolValue ? (short)1 : (short)0;
}
}
// 返回修改后的 SQL 和参数
return new System.Collections.Generic.KeyValuePair<string, SugarParameter[]>(sql, parameters);
};
return sqlSugar;
});

View File

@ -184,8 +184,28 @@ namespace OpenAuth.WebApi
{
DbType = dbType.Value,
ConnectionString = connectionString,
IsAutoCloseConnection = true
IsAutoCloseConnection = true
}, db => { db.Aop.OnLogExecuting = (sql, pars) => { logger.LogInformation(sql); }; });
if(dbType.Value != SqlSugar.DbType.PostgreSQL){
return sqlSugar;
}
// 配置bool类型转换为smallint
sqlSugar.Aop.OnExecutingChangeSql = (sql, parameters) =>
{
foreach (var param in parameters)
{
if (param.Value is bool boolValue)
{
param.DbType = System.Data.DbType.Int16;
// 将 bool 转换为 smallint
param.Value = boolValue ? (short)1 : (short)0;
}
}
// 返回修改后的 SQL 和参数
return new System.Collections.Generic.KeyValuePair<string, SugarParameter[]>(sql, parameters);
};
return sqlSugar;
});