Update exp to sql

This commit is contained in:
sunkaixuan 2023-05-04 09:30:58 +08:00
parent 7c5bdeeb9d
commit c2120f3e44
2 changed files with 48 additions and 19 deletions

View File

@ -642,9 +642,12 @@ namespace SqlSugar
{ {
var managers = (this.QueryBuilder.Includes as List<object>); var managers = (this.QueryBuilder.Includes as List<object>);
if (IsSelectNavQuery()) if (IsSelectNavQuery())
{
if (result.HasValue())
{ {
SelectNavQuery(result, managers); SelectNavQuery(result, managers);
} }
}
else else
{ {
foreach (var it in managers) foreach (var it in managers)
@ -664,8 +667,35 @@ namespace SqlSugar
var manager = it; var manager = it;
var p = it.GetType().GetProperty("RootList"); var p = it.GetType().GetProperty("RootList");
var tType = it.GetType().GenericTypeArguments[0]; var tType = it.GetType().GenericTypeArguments[0];
var columns = this.Context.EntityMaintenance.GetEntityInfo(tType).Columns; var columns = this.Context.EntityMaintenance.GetEntityInfo(tType)
.Columns
.Where(it=> this.QueryBuilder.AppendNavInfo.Result.First().result.ContainsKey("SugarNav_" + it.PropertyName))
.ToList();
var listType = typeof(List<>).MakeGenericType(tType); var listType = typeof(List<>).MakeGenericType(tType);
var outList=SelectNavQuery_SetList(result, it, p, tType, columns, listType);
it.GetType().GetMethod("Execute").Invoke(it, null);
SelectNavQuery_MappingList(it,result, outList);
}
}
private void SelectNavQuery_MappingList<TResult>(object it,List<TResult> result, IList outList)
{
for (int i = 0; i < result.Count; i++)
{
var resultItem = result[i];
var outListItem = outList[i];
foreach (var item in this.QueryBuilder.AppendNavInfo.MappingNavProperties)
{
if (item.Value.ExpressionList.Count > 0)
{
}
}
}
}
private IList SelectNavQuery_SetList<TResult>(List<TResult> result, object it, PropertyInfo p, Type tType, List<EntityColumnInfo> columns, Type listType)
{
var outList = Activator.CreateInstance(listType); var outList = Activator.CreateInstance(listType);
p.SetValue(it, outList); p.SetValue(it, outList);
var index = 0; var index = 0;
@ -682,8 +712,7 @@ namespace SqlSugar
(outList as IList).Add(addItem); (outList as IList).Add(addItem);
index++; index++;
} }
it.GetType().GetMethod("Execute").Invoke(it, null); return outList as IList;
}
} }
private bool IsSelectNavQuery() private bool IsSelectNavQuery()

View File

@ -277,7 +277,7 @@ namespace SqlSugar
selector = GetNewExpressionValue(rightExpression.Arguments[0]); selector = GetNewExpressionValue(rightExpression.Arguments[0]);
} }
var selectorExp = rightExpression.Arguments[0]; var selectorExp = rightExpression.Arguments[0];
if (selector.Contains(".") && selectorExp is LambdaExpression) if (hasMethodCallWithName==false&&selector.Contains(".") && selectorExp is LambdaExpression)
{ {
var selectorExpLam = (selectorExp as LambdaExpression); var selectorExpLam = (selectorExp as LambdaExpression);
var name=(selectorExpLam.Parameters[0] as ParameterExpression).Name; var name=(selectorExpLam.Parameters[0] as ParameterExpression).Name;