Browse Source

Merge branch 'dev' of github.com:sunkaixuan/SqlSugar

pull/12/MERGE
sunkaixuan 7 years ago
parent
commit
1231fc868a
  1. 12
      Src/Asp.Net/SqlServerTest/UnitTest/Query/SelectQuery.cs
  2. 4
      Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/BaseResolve.cs
  3. 23
      Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/SubResolve.cs

12
Src/Asp.Net/SqlServerTest/UnitTest/Query/SelectQuery.cs

@ -106,6 +106,18 @@ namespace OrmTest.UnitTest
new List<SugarParameter>() {
new SugarParameter("@Const0",false)
}, t6.Key, t6.Value, "select t6 Error");
var t7 = db.Queryable<Student>().Select(it=>new DataTestInfo2() {
Bool1=SqlFunc.IIF(SqlFunc.Subqueryable<Student>().Where(x=>x.Id
==it.Id).Any(),true,false)
}).ToSql();
base.Check("SELECT ( CASE WHEN (EXISTS ( SELECT * FROM [STudent] WHERE ( [ID] = [it].[ID] ) )) THEN @MethodConst0 ELSE @MethodConst1 END ) AS [Bool1] FROM [STudent] it ",
new List<SugarParameter>() {
new SugarParameter("@MethodConst0",true),
new SugarParameter("@MethodConst1",false)
}, t7.Key, t7.Value, "select t7 Error");
#endregion

4
Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/BaseResolve.cs

@ -264,6 +264,10 @@ namespace SqlSugar
{
this.Context.Parameters.AddRange(newContext.Parameters);
}
if (newContext.SingleTableNameSubqueryShortName.HasValue())
{
this.Context.SingleTableNameSubqueryShortName = newContext.SingleTableNameSubqueryShortName;
}
var methodCallExpressionArgs = new MethodCallExpressionArgs()
{
IsMember = true,

23
Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/SubResolve.cs

@ -22,14 +22,31 @@ namespace SqlSugar
this.context = context;
var currentExpression = expression;
allMethods.Add(currentExpression);
if (context.IsSingle && oppsiteExpression != null&& oppsiteExpression is MemberExpression)
if (context.IsSingle && oppsiteExpression != null && oppsiteExpression is MemberExpression)
{
var childExpression = (oppsiteExpression as MemberExpression).Expression;
this.context.SingleTableNameSubqueryShortName = (childExpression as ParameterExpression).Name;
}
else if (context.IsSingle)
{
this.context.SingleTableNameSubqueryShortName = (context.Expression as LambdaExpression).Parameters.First().Name;
if (context.Expression is LambdaExpression)
{
this.context.SingleTableNameSubqueryShortName = (context.Expression as LambdaExpression).Parameters.First().Name;
}
else if (context.Expression is MethodCallExpression)
{
var meExp = ((context.Expression as MethodCallExpression).Object as MethodCallExpression).Arguments[0] as LambdaExpression;
var selfParameterName = meExp.Parameters.First().Name;
context.SingleTableNameSubqueryShortName = (((meExp.Body as BinaryExpression).Left as MemberExpression).Expression as ParameterExpression).Name;
if (context.SingleTableNameSubqueryShortName == selfParameterName)
{
context.SingleTableNameSubqueryShortName = (((meExp.Body as BinaryExpression).Right as MemberExpression).Expression as ParameterExpression).Name;
}
}
else
{
Check.Exception(true, "I'm sorry I can't parse the current expression");
}
}
while (currentExpression != null)
{
@ -69,7 +86,7 @@ namespace SqlSugar
isubList.Insert(0, new SubBegin());
if (isubList.Any(it => it is SubSelect))
{
isubList.Add(new SubTop() { Context=this.context });
isubList.Add(new SubTop() { Context = this.context });
}
if (isubList.Any(it => it is SubAny || it is SubNotAny))
{

Loading…
Cancel
Save