Browse Source

Update Core

pull/19/head
sunkaixuan 3 years ago
parent
commit
05b6c04479
  1. 13
      Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/Common/ExpressionTool.cs
  2. 14
      Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ResolveItems/BaseResolve.cs
  3. 24
      Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ResolveItems/OneToManyNavgateExpression.cs

13
Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/Common/ExpressionTool.cs

@ -53,6 +53,19 @@ namespace SqlSugar
}
}
public static List<ParameterExpression> ExpressionParameters(Expression expression)
{
List<ParameterExpression> parameters = null;
if (expression is LambdaExpression)
{
if ((expression as LambdaExpression).Parameters != null)
{
parameters = (expression as LambdaExpression).Parameters.ToList();
}
}
return parameters;
}
public static object GetValue(object value,ExpressionContext context)
{
if (value == null) return value;

14
Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ResolveItems/BaseResolve.cs

@ -322,6 +322,7 @@ namespace SqlSugar
public string GetNewExpressionValue(Expression item)
{
var newContext = this.Context.GetCopyContextWithMapping();
newContext.SugarContext = this.Context.SugarContext;
newContext.Resolve(item, this.Context.IsJoin ? ResolveExpressType.WhereMultiple : ResolveExpressType.WhereSingle);
this.Context.Index = newContext.Index;
this.Context.ParameterIndex = newContext.ParameterIndex;
@ -331,6 +332,19 @@ namespace SqlSugar
}
return newContext.Result.GetResultString();
}
public string GetNewExpressionValue(Expression item,ResolveExpressType type)
{
var newContext = this.Context.GetCopyContextWithMapping();
newContext.SugarContext = this.Context.SugarContext;
newContext.Resolve(item, type);
this.Context.Index = newContext.Index;
this.Context.ParameterIndex = newContext.ParameterIndex;
if (newContext.Parameters.HasValue())
{
this.Context.Parameters.AddRange(newContext.Parameters);
}
return newContext.Result.GetResultString();
}
protected void ResolveNewExpressions(ExpressionParameter parameter, Expression item, string asName)
{

24
Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ResolveItems/OneToManyNavgateExpression.cs

@ -14,6 +14,7 @@ namespace SqlSugar
private EntityInfo ProPertyEntity;
private Navigate Navigat;
public string ShorName;
public string PropertyShortName;
private string MemberName;
private string MethodName;
private string whereSql;
@ -41,8 +42,13 @@ namespace SqlSugar
result = ValidateNav(result, memberExp.Arguments[0] as MemberExpression, memberExp.Arguments[0]);
if (memberExp.Arguments.Count > 1)
{
var pars = ExpressionTool.ExpressionParameters(memberExp.Arguments.Last());
if (pars != null&& ProPertyEntity!=null&& pars.Any(z => z.Type == ProPertyEntity.Type))
{
PropertyShortName = pars.First(z => z.Type == ProPertyEntity.Type).Name;
}
whereSql = GetWhereSql(memberExp);
}
}
}
}
return result;
@ -51,8 +57,16 @@ namespace SqlSugar
private string GetWhereSql(MethodCallExpression memberExp)
{
var whereExp = memberExp.Arguments[1];
var result= this.methodCallExpressionResolve.GetNewExpressionValue(whereExp);
return result;
if (PropertyShortName.HasValue()&& Navigat!=null&& Navigat.NavigatType==NavigateType.OneToMany)
{
var result = this.methodCallExpressionResolve.GetNewExpressionValue(whereExp, ResolveExpressType.WhereMultiple);
return result;
}
else
{
var result = this.methodCallExpressionResolve.GetNewExpressionValue(whereExp);
return result;
}
}
private bool ValidateNav(bool result, MemberExpression memberExp, Expression childExpression)
@ -129,6 +143,10 @@ namespace SqlSugar
pk = queryable.QueryBuilder.Builder.GetTranslationColumnName(pk);
name = queryable.QueryBuilder.Builder.GetTranslationColumnName(name);
//selectName = queryable.QueryBuilder.Builder.GetTranslationColumnName(selectName);
if (PropertyShortName.HasValue())
{
queryable.QueryBuilder.TableShortName = PropertyShortName;
}
mapper.Sql = queryable
.AS(this.ProPertyEntity.DbTableName)
.WhereIF(!string.IsNullOrEmpty(whereSql), whereSql)

Loading…
Cancel
Save