diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MemberInitExpressionResolve.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MemberInitExpressionResolve.cs index 58c6efb72..603562c81 100644 --- a/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MemberInitExpressionResolve.cs +++ b/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MemberInitExpressionResolve.cs @@ -87,7 +87,7 @@ namespace SqlSugar var result = this.Context.DbMehtods.IIF(new MethodCallExpressionModel() { Args = new List() { - new MethodCallExpressionArgs(){ IsMember=true, MemberName=parameter.CommonTempData.ObjToString()+"=1" }, + new MethodCallExpressionArgs(){ IsMember=true, MemberName=parameter.CommonTempData.ObjToString()+"=1",Type=UtilConstants.BoolType }, new MethodCallExpressionArgs(){ IsMember=true,MemberName=AppendParameter(0) }, new MethodCallExpressionArgs(){ IsMember=true, MemberName=AppendParameter(1) } } diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/UnaryExpressionResolve.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/UnaryExpressionResolve.cs index 7f9c41d96..9b31e202c 100644 --- a/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/UnaryExpressionResolve.cs +++ b/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/UnaryExpressionResolve.cs @@ -150,7 +150,7 @@ namespace SqlSugar var result= this.Context.DbMehtods.IIF(new MethodCallExpressionModel() { Args = new List() { - new MethodCallExpressionArgs(){ IsMember=true, MemberName=parameter.CommonTempData.ObjToString()+"=1" }, + new MethodCallExpressionArgs(){ IsMember=true, MemberName=parameter.CommonTempData.ObjToString()+"=1",Type=UtilConstants.BoolType }, new MethodCallExpressionArgs(){ IsMember=true,MemberName=AppendParameter(0) }, new MethodCallExpressionArgs(){ IsMember=true, MemberName=AppendParameter(1) } } diff --git a/Src/Asp.Net/SqlSugar/Realization/PostgreSQL/SqlBuilder/PostgreSQLExpressionContext.cs b/Src/Asp.Net/SqlSugar/Realization/PostgreSQL/SqlBuilder/PostgreSQLExpressionContext.cs index 833db234a..1f4c13a73 100644 --- a/Src/Asp.Net/SqlSugar/Realization/PostgreSQL/SqlBuilder/PostgreSQLExpressionContext.cs +++ b/Src/Asp.Net/SqlSugar/Realization/PostgreSQL/SqlBuilder/PostgreSQLExpressionContext.cs @@ -96,6 +96,19 @@ namespace SqlSugar } public class PostgreSQLMethod : DefaultDbMethod, IDbMethods { + public override string IIF(MethodCallExpressionModel model) + { + var parameter = model.Args[0]; + var parameter2 = model.Args[1]; + var parameter3 = model.Args[2]; + if (parameter.Type == UtilConstants.BoolType) + { + parameter.MemberName = parameter.MemberName.ToString().Replace("=1", "=true"); + parameter2.MemberName = false; + parameter3.MemberName = true; + } + return string.Format("( CASE WHEN {0} THEN {1} ELSE {2} END )", parameter.MemberName, parameter2.MemberName, parameter3.MemberName); + } public override string DateValue(MethodCallExpressionModel model) { var parameter = model.Args[0];