Browse Source

4.6.0.1

pull/12/MERGE
sunkaixuan 7 years ago
parent
commit
411296e20a
  1. 6
      Src/Asp.Net/MySqlTest/Demos/1_Query.cs
  2. 2
      Src/Asp.Net/SqlServerTest/Demos/1_Query.cs
  3. 13
      Src/Asp.Net/SqlSugar/ExpressionsToSql/CaseWhen/CaseWhenResolve.cs
  4. 24
      Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs
  5. 1
      Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/IDbMethods.cs
  6. 11
      Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs

6
Src/Asp.Net/MySqlTest/Demos/1_Query.cs

@ -232,6 +232,12 @@ namespace OrmTest.Demo
var getDay1List = db.Queryable<Student>().Where(it => it.CreateTime.Value.Hour == 1).ToList();
var getDateAdd = db.Queryable<Student>().Where(it => it.CreateTime.Value.AddDays(1) == DateTime.Now).ToList();
var getDateIsSame = db.Queryable<Student>().Where(it => SqlFunc.DateIsSame(DateTime.Now, DateTime.Now, DateType.Hour)).ToList();
var test2 = db.Queryable<Student, School>((st, sc) => st.SchoolId == sc.Id)
.Where(st =>
SqlFunc.IF(st.Id > 1)
.Return(st.Id)
.ElseIF(st.Id == 1)
.Return(st.SchoolId).End(st.Id) == 1).Select(st => st).ToList();
}
public static void Page()
{

2
Src/Asp.Net/SqlServerTest/Demos/1_Query.cs

@ -289,7 +289,7 @@ namespace OrmTest.Demo
SqlFunc.IF(st.Id > 1)
.Return(st.Id)
.ElseIF(st.Id == 1)
.Return(st.SchoolId).End(st.Id) == 1).ToList();
.Return(st.SchoolId).End(st.Id) == 1).Select(st=>st).ToList();
var test3 = db.Queryable<DataTestInfo2>().Select(it => it.Bool1).ToSql();
var test4 = db.Queryable<DataTestInfo2>().Select(it => new { b=it.Bool1 }).ToSql();
}

13
Src/Asp.Net/SqlSugar/ExpressionsToSql/CaseWhen/CaseWhenResolve.cs

@ -16,7 +16,6 @@ namespace SqlSugar
{
List<MethodCallExpression> allMethods = new List<MethodCallExpression>();
private ExpressionContext context = null;
private bool hasWhere;
public CaseWhenResolve(MethodCallExpression expression, ExpressionContext context, Expression oppsiteExpression)
{
this.context = context;
@ -42,7 +41,17 @@ namespace SqlSugar
public string GetSql()
{
return "";
allMethods.Reverse();
List<KeyValuePair<string, string>> sqls = new List<KeyValuePair<string, string>>();
foreach (var methodExp in allMethods)
{
var isFirst = allMethods.First() == methodExp;
var isLast= allMethods.Last() == methodExp;
var sql= SubTools.GetMethodValue(this.context, methodExp.Arguments[0],this.context.IsSingle?ResolveExpressType.WhereSingle:ResolveExpressType.WhereMultiple);
sqls.Add(new KeyValuePair<string, string>(methodExp.Method.Name, sql));
}
var result= this.context.DbMehtods.CaseWhen(sqls);
return result;
}
}
}

24
Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs

@ -324,5 +324,29 @@ namespace SqlSugar
{
return "GETDATE()";
}
public virtual string CaseWhen(List<KeyValuePair<string, string>> sqls)
{
StringBuilder reslut = new StringBuilder();
foreach (var item in sqls)
{
if (item.Key == "IF")
{
reslut.AppendFormat(" ( CASE WHEN {0} ", item.Value);
}
else if (item.Key == "End")
{
reslut.AppendFormat("ELSE {0} END )", item.Value);
}
else if (item.Key == "Return")
{
reslut.AppendFormat(" THEN {0} ", item.Value);
}
else {
reslut.AppendFormat(" WHEN {0} ", item.Value);
}
}
return reslut.ToString();
}
}
}

1
Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/IDbMethods.cs

@ -36,6 +36,7 @@ namespace SqlSugar
string ToGuid(MethodCallExpressionModel model);
string ToDouble(MethodCallExpressionModel model);
string ToBool(MethodCallExpressionModel model);
string CaseWhen(List<KeyValuePair<string,string>> sqls);
string Substring(MethodCallExpressionModel model);
string ToDate(MethodCallExpressionModel model);
string ToTime(MethodCallExpressionModel model);

11
Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs

@ -56,7 +56,16 @@ namespace SqlSugar
return;
}
else if (IsIfElse(express, methodName)) {
List<Expression> expList = new List<Expression>();
CaseWhenResolve caseResole = new CaseWhenResolve(express, this.Context, parameter.OppsiteExpression);
var appendSql = caseResole.GetSql();
if (this.Context.ResolveType.IsIn(ResolveExpressType.SelectMultiple, ResolveExpressType.SelectSingle))
{
parameter.BaseParameter.CommonTempData = appendSql;
}
else
{
base.AppendValue(parameter, isLeft, appendSql);
}
return;
}
if (IsContainsArray(express, methodName, isValidNativeMethod))

Loading…
Cancel
Save