Browse Source

Update exp to sql

pull/2/head
SUNKAIXUAN 4 years ago
parent
commit
3326d0b278
  1. 5
      Src/Asp.Net/SqlServerTest/Demo/Demo1_Queryable.cs
  2. 1
      Src/Asp.Net/SqlSugar/Abstract/SqlBuilderProvider/QueryBuilder.cs
  3. 3
      Src/Asp.Net/SqlSugar/ExpressionsToSql/ExpressionContext.cs
  4. 5
      Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/SubResolve.cs
  5. 1
      Src/Asp.Net/SqlSugar/Interface/ILambdaExpressions.cs

5
Src/Asp.Net/SqlServerTest/Demo/Demo1_Queryable.cs

@ -124,6 +124,11 @@ namespace OrmTest
customName2 = SqlFunc.Subqueryable<Custom>().Where("it.CustomId = id").Where(s => true).Select(s => s.Name)
}).ToList();
var list1 = db.Queryable<Order>().Select(it => new
{
id = SqlFunc.Subqueryable<Custom>().Where(s => s.Id == 1).Sum(s => s.Id) * 1
}).ToList();
var list2 = db.Queryable<Order>().Where(it =>
SqlFunc.Subqueryable<OrderItem>()
.LeftJoin<OrderItem>((i,y)=>i.ItemId==y.ItemId)

1
Src/Asp.Net/SqlSugar/Abstract/SqlBuilderProvider/QueryBuilder.cs

@ -238,6 +238,7 @@ namespace SqlSugar
{
resolveExpress.PgSqlIsAutoToLower = true;
}
resolveExpress.RootExpression = expression;
resolveExpress.JoinQueryInfos = Builder.QueryBuilder.JoinQueryInfos;
resolveExpress.IsSingle = IsSingle();
resolveExpress.MappingColumns = Context.MappingColumns;

3
Src/Asp.Net/SqlSugar/ExpressionsToSql/ExpressionContext.cs

@ -45,6 +45,7 @@ namespace SqlSugar
public IgnoreColumnList IgnoreComumnList { get; set; }
public bool PgSqlIsAutoToLower { get; set; }
public List<SqlFuncExternal> SqlFuncServices { get; set; }
public Expression RootExpression { get; set; }
public bool IsSingle
{
get
@ -129,6 +130,7 @@ namespace SqlSugar
copyContext.ParameterIndex = this.ParameterIndex;
copyContext.PgSqlIsAutoToLower = this.PgSqlIsAutoToLower;
copyContext.IsSingle = this.IsSingle;
copyContext.RootExpression = this.RootExpression;
return copyContext;
}
public ExpressionContext GetCopyContextWithMapping()
@ -144,6 +146,7 @@ namespace SqlSugar
copyContext.RefreshMapping = this.RefreshMapping;
copyContext.PgSqlIsAutoToLower = this.PgSqlIsAutoToLower;
copyContext.IsSingle = this.IsSingle;
copyContext.RootExpression = this.RootExpression;
return copyContext;
}
#endregion

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

@ -63,6 +63,11 @@ namespace SqlSugar
context.SingleTableNameSubqueryShortName = (((meExp.Body as BinaryExpression).Right as MemberExpression).Expression as ParameterExpression).Name;
}
}
else if (context.RootExpression!=null&&context.Expression.GetType().Name == "SimpleBinaryExpression")
{
var name = (this.context.RootExpression as LambdaExpression).Parameters[0].Name;
context.SingleTableNameSubqueryShortName = name;
}
else
{
Check.Exception(true, "I'm sorry I can't parse the current expression");

1
Src/Asp.Net/SqlSugar/Interface/ILambdaExpressions.cs

@ -27,6 +27,7 @@ namespace SqlSugar
Action<Type> InitMappingInfo { get; set; }
Action RefreshMapping { get; set; }
bool PgSqlIsAutoToLower { get; set; }
Expression RootExpression { get; set; }
string GetAsString(string fieldName, string fieldValue);
void Resolve(Expression expression, ResolveExpressType resolveType);

Loading…
Cancel
Save