Update exp to sql

This commit is contained in:
sunkaixuna 2022-01-15 17:57:22 +08:00
parent d603994ac6
commit d26327a39f
2 changed files with 34 additions and 3 deletions

View File

@ -102,6 +102,21 @@ namespace OrmTest
a = string.IsNullOrEmpty(it.Name) a = string.IsNullOrEmpty(it.Name)
}).ToList(); }).ToList();
var blist4 = Db.Queryable<BoolTest3>().Select(it => new BoolTest3()
{
a = SqlFunc.IIF(it.a == true, true, false)
}).ToList();
var blist5 = Db.Queryable<BoolTest3>().Select(it => new BoolTest3()
{
a = SqlFunc.IF(it.a == true).Return(true).End(false)
}).ToList();
var blist6 = Db.Queryable<BoolTest3>().Select(it => new BoolTest3()
{
a =it.a==true?true:false
}).ToList();
var db = Db; var db = Db;
db.CodeFirst.InitTables<UserInfo, UserIpRuleInfo>(); db.CodeFirst.InitTables<UserInfo, UserIpRuleInfo>();
db.Deleteable<UserInfo>().ExecuteCommand(); db.Deleteable<UserInfo>().ExecuteCommand();

View File

@ -483,7 +483,7 @@ namespace SqlSugar
} }
} }
} }
else if (item.Type == UtilConstants.BoolType && item is MethodCallExpression) else if (item.Type == UtilConstants.BoolType && item is MethodCallExpression && IsNotCaseExpression(item))
{ {
this.Expression = item; this.Expression = item;
this.Start(); this.Start();
@ -518,6 +518,22 @@ namespace SqlSugar
} }
} }
private static bool IsNotCaseExpression(Expression item)
{
if ((item as MethodCallExpression).Method.Name == "IIF")
{
return false;
}
else if ((item as MethodCallExpression).Method.Name == "End"&&item.ToString().Contains("IF("))
{
return false;
}
else
{
return true;
}
}
private Dictionary<string, string> GetMappingColumns(Expression currentExpression) private Dictionary<string, string> GetMappingColumns(Expression currentExpression)
{ {
Dictionary<string, string> result = new Dictionary<string, string>(); Dictionary<string, string> result = new Dictionary<string, string>();