Browse Source

-

pull/12/MERGE
sunkaixuan 7 years ago
parent
commit
40d68186c7
  1. 3
      Src/Asp.Net/SqlServerTest/Demos/1_Query.cs
  2. 35
      Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubOrderBy.cs
  3. 4
      Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/SubTools.cs
  4. 9
      Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Subquerable.cs

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

@ -47,6 +47,9 @@ namespace OrmTest.Demo
var getAll9 = db.Queryable<Student>().Where(it => SqlFunc.Subqueryable<School>().Where(s => s.Id == it.Id).Count()==1).ToList();
var getAll10 = db.Queryable<Student>().Where(it => SqlFunc.Subqueryable<School>().Where(s => s.Id == it.Id).OrderBy(s=>s.Id).Select(s=>s.Id) == 1).ToList();
var getAll14 = db.Queryable<Student>().Where(it => SqlFunc.Subqueryable<School>().Where(s => s.Id == it.Id).OrderByDesc(s => s.Id).Select(s => s.Id) == 1).ToList();
var getAll8= db.Queryable<Student>().Where(it => SqlFunc.Subqueryable<School>().Where(s => s.Id == it.Id).Where(s=>s.Name==it.Name).NotAny()).ToList();
var getAll1 = db.Queryable<Student>().Where(it => it.Id == SqlFunc.Subqueryable<School>().Where(s => s.Id == it.Id).Select(s => s.Id)).ToList();

35
Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubOrderBy.cs

@ -41,4 +41,39 @@ namespace SqlSugar
return result;
}
}
public class SubOrderByDesc : ISubOperation
{
public string Name
{
get { return "OrderByDesc"; }
}
public Expression Expression
{
get; set;
}
public int Sort
{
get
{
return 480;
}
}
public ExpressionContext Context
{
get; set;
}
public string GetValue(Expression expression)
{
var exp = expression as MethodCallExpression;
var argExp = exp.Arguments[0];
var result = "ORDER BY " + SubTools.GetMethodValue(this.Context, argExp, ResolveExpressType.FieldSingle)+" DESC";
var selfParameterName = this.Context.GetTranslationColumnName((argExp as LambdaExpression).Parameters.First().Name) + UtilConstants.Dot;
result = result.Replace(selfParameterName, string.Empty);
return result;
}
}
}

4
Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/SubTools.cs

@ -22,7 +22,9 @@ namespace SqlSugar
new SubFromTable(){ Context=Context },
new SubCount(){ Context=Context },
new SubMax(){ Context=Context },
new SubMin(){ Context=Context }
new SubMin(){ Context=Context },
new SubOrderBy(){ Context=Context },
new SubOrderByDesc(){ Context=Context }
};
}

9
Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Subquerable.cs

@ -16,7 +16,14 @@ namespace SqlSugar
{
return this;
}
public Subqueryable<T> OrderBy(Func<T, object> expression)
{
return this;
}
public Subqueryable<T> OrderByDesc(Func<T, object> expression)
{
return this;
}
public TResult Select<TResult>(Func<T, TResult> expression) where TResult :struct
{
return default(TResult);

Loading…
Cancel
Save