mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-07-15 23:13:42 +08:00
Subquery Bug
This commit is contained in:
parent
b7d5bd48d9
commit
9d2a67dd7a
@ -116,6 +116,14 @@ namespace OrmTest.UnitTest
|
|||||||
|
|
||||||
var t12 = db.Queryable<Student>().Where(it=>it.Id!=null).ToSql();
|
var t12 = db.Queryable<Student>().Where(it=>it.Id!=null).ToSql();
|
||||||
base.Check("SELECT [ID],[SchoolId],[Name],[CreateTime] FROM [STudent] WHERE ( [ID] IS NOT NULL )", null, t12.Key, t12.Value, "single t12 error");
|
base.Check("SELECT [ID],[SchoolId],[Name],[CreateTime] FROM [STudent] WHERE ( [ID] IS NOT NULL )", null, t12.Key, t12.Value, "single t12 error");
|
||||||
|
|
||||||
|
var id = 1;
|
||||||
|
var t13 = db.Queryable<Student>().Where(it => SqlFunc.Subqueryable<School>().Where(s => s.Id == it.Id&&s.Id==id).Max(s => s.Id) == 1).ToSql();
|
||||||
|
base.Check("SELECT [ID],[SchoolId],[Name],[CreateTime] FROM [STudent] it WHERE ((SELECT MAX([Id]) FROM [School] WHERE (( [Id] = [it].[ID] ) AND ( [Id] = @Id0 ))) = @Const1 )",
|
||||||
|
new List<SugarParameter>() {
|
||||||
|
new SugarParameter("@Id0",1),
|
||||||
|
new SugarParameter("@Const1",1)
|
||||||
|
}, t13.Key, t13.Value, "single t13 error ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
var exp = expression as MethodCallExpression;
|
var exp = expression as MethodCallExpression;
|
||||||
var argExp= exp.Arguments[0];
|
var argExp= exp.Arguments[0];
|
||||||
var result= "WHERE "+SubTools.GetMethodValue(Context, argExp, ResolveExpressType.WhereMultiple);
|
var result= "WHERE "+SubTools.GetMethodValue(Context, argExp, ResolveExpressType.WhereMultiple);;
|
||||||
var selfParameterName = Context.GetTranslationColumnName((argExp as LambdaExpression).Parameters.First().Name)+UtilConstants.Dot;
|
var selfParameterName = Context.GetTranslationColumnName((argExp as LambdaExpression).Parameters.First().Name)+UtilConstants.Dot;
|
||||||
result = result.Replace(selfParameterName,string.Empty);
|
result = result.Replace(selfParameterName,string.Empty);
|
||||||
return result;
|
return result;
|
||||||
|
@ -11,7 +11,7 @@ namespace SqlSugar
|
|||||||
public static List<ISubOperation> SubItems(ExpressionContext Context)
|
public static List<ISubOperation> SubItems(ExpressionContext Context)
|
||||||
{
|
{
|
||||||
|
|
||||||
return new List<ISubOperation>()
|
return new List<ISubOperation>()
|
||||||
{
|
{
|
||||||
new SubSelect() { Context=Context },
|
new SubSelect() { Context=Context },
|
||||||
new SubWhere(){ Context=Context },
|
new SubWhere(){ Context=Context },
|
||||||
@ -37,6 +37,8 @@ namespace SqlSugar
|
|||||||
newContext.Resolve(item, type);
|
newContext.Resolve(item, type);
|
||||||
context.Index = newContext.Index;
|
context.Index = newContext.Index;
|
||||||
context.ParameterIndex = newContext.ParameterIndex;
|
context.ParameterIndex = newContext.ParameterIndex;
|
||||||
|
if (newContext.Parameters.IsValuable())
|
||||||
|
context.Parameters.AddRange(newContext.Parameters);
|
||||||
return newContext.Result.GetResultString();
|
return newContext.Result.GetResultString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user