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

This commit is contained in:
wintel 2025-02-23 21:11:42 +08:00
parent 8608aea1e9
commit b6a2707097
6 changed files with 82 additions and 10 deletions

View File

@ -79,6 +79,21 @@ namespace OpenAuth.App.Test
ConnectionString = connectionString,
IsAutoCloseConnection = true
});
// 配置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,23 @@ 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
});
// 配置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,22 @@ namespace OpenAuth.Mvc
ConnectionString = connectionString,
IsAutoCloseConnection = true
}, db => { db.Aop.OnLogExecuting = (sql, pars) => { logger.LogInformation(sql); }; });
// 配置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

@ -7,8 +7,8 @@
"AllowedHosts": "*",
"DataProtection": "temp-keys/",
"ConnectionStrings": {
"OpenAuthDBContext": "Data Source=.;Encrypt=false;Initial Catalog=OpenAuthDB;User=sa;Password=000000"
//"OpenAuthDBContext": "server=127.0.0.1;user id=root;database=openauthdb;password=000000" //my sql
// "OpenAuthDBContext": "Data Source=.;Encrypt=false;Initial Catalog=OpenAuthDB;User=sa;Password=000000"
"OpenAuthDBContext": "server=127.0.0.1;user id=root;database=openauthdb;password=000000" //my sql
//"OpenAuthDBContext": "Host=localhost;Port=5432;Database=OpenAuth;Username=postgres;Password=123;" //PostgreSQL
},
"AppSetting": {
@ -17,7 +17,7 @@
"SSOPassport": "http://localhost:52789",
"Version": "1.0", //demopost
"DbTypes": {
"OpenAuthDBContext": "SqlServer" //SqlServerMySqlOraclePostgreSQL
"OpenAuthDBContext": "MySql" //SqlServerMySqlOraclePostgreSQL
},
"RedisConf": "redistest.cq-p.com.cn:8001,password=share_redis@123", //redis
"HttpHost": "http://*:1802" //

View File

@ -85,6 +85,21 @@ namespace OpenAuth.Repository.Test
ConnectionString = connectionString,
IsAutoCloseConnection = true
});
// 配置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,24 @@ namespace OpenAuth.WebApi
{
DbType = dbType.Value,
ConnectionString = connectionString,
IsAutoCloseConnection = true
IsAutoCloseConnection = true
}, db => { db.Aop.OnLogExecuting = (sql, pars) => { logger.LogInformation(sql); }; });
// 配置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;
});