mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-24 07:22:57 +08:00
db.Queryable.Includes.Select.ToList
This commit is contained in:
parent
c9961dc6c8
commit
4bc0f702d7
@ -582,8 +582,10 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
var value = item.Value;
|
var value = item.Value;
|
||||||
var expressionTree = new ExpressionTreeVisitor().GetExpressions(value);
|
var expressionTree = new ExpressionTreeVisitor().GetExpressions(value);
|
||||||
if (expressionTree.Any())
|
var isSqlMethod = ExpressionTool.GetMethodName(expressionTree.Last()).IsIn("Any", "Count");
|
||||||
|
if (expressionTree.Any()&&isSqlMethod==false)
|
||||||
{
|
{
|
||||||
|
|
||||||
var name = ExpressionTool.GetMemberName(expressionTree.First());
|
var name = ExpressionTool.GetMemberName(expressionTree.First());
|
||||||
if (name != null && entityColumns.Any(it => it.Navigat != null && it.PropertyName == name))
|
if (name != null && entityColumns.Any(it => it.Navigat != null && it.PropertyName == name))
|
||||||
{
|
{
|
||||||
@ -704,7 +706,7 @@ namespace SqlSugar
|
|||||||
var obj = comExp.Compile();
|
var obj = comExp.Compile();
|
||||||
// 传递参数值
|
// 传递参数值
|
||||||
var leftValue = obj.DynamicInvoke(rightObject);
|
var leftValue = obj.DynamicInvoke(rightObject);
|
||||||
leftObject.GetType().GetProperty(leftName).SetValue(leftObject, leftValue);
|
UtilMethods.SetAnonymousObjectPropertyValue(leftObject, leftName, rightValue);
|
||||||
// // 重新构造Lambda表达式,将参数替换为新的参数,方法调用替换为新的方法调用
|
// // 重新构造Lambda表达式,将参数替换为新的参数,方法调用替换为新的方法调用
|
||||||
// var newExpression = Expression.Lambda<Func<X, List<int>>>(newMethodCallExpr, paramExpr);
|
// var newExpression = Expression.Lambda<Func<X, List<int>>>(newMethodCallExpr, paramExpr);
|
||||||
// Expression.Call(callExp, (callExp as MethodCallExpression).Method,new )
|
// Expression.Call(callExp, (callExp as MethodCallExpression).Method,new )
|
||||||
@ -713,12 +715,13 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
leftObject.GetType().GetProperty(leftName).SetValue(leftObject, rightValue);
|
//leftObject.GetType().GetProperty(leftName).SetValue(leftObject, rightValue);
|
||||||
|
UtilMethods.SetAnonymousObjectPropertyValue(leftObject, leftName, rightValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private IList SelectNavQuery_SetList<TResult>(List<TResult> result, object it, PropertyInfo p, Type tType, List<EntityColumnInfo> columns, Type listType)
|
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);
|
||||||
|
@ -148,6 +148,7 @@ namespace SqlSugar
|
|||||||
string memberName = expression.Members[i].Name;
|
string memberName = expression.Members[i].Name;
|
||||||
if (this.Context?.SugarContext?.QueryBuilder?.AppendNavInfo?.MappingNavProperties?.ContainsKey(memberName) == true)
|
if (this.Context?.SugarContext?.QueryBuilder?.AppendNavInfo?.MappingNavProperties?.ContainsKey(memberName) == true)
|
||||||
{
|
{
|
||||||
|
++i;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
++i;
|
++i;
|
||||||
|
@ -17,6 +17,28 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
public class UtilMethods
|
public class UtilMethods
|
||||||
{
|
{
|
||||||
|
public static object SetAnonymousObjectPropertyValue(object obj, string propertyName, object propertyValue)
|
||||||
|
{
|
||||||
|
if (obj.GetType().IsAnonymousType()) // 判断是否为匿名对象
|
||||||
|
{
|
||||||
|
var objType = obj.GetType();
|
||||||
|
var objFields = objType.GetFields(BindingFlags.Instance | BindingFlags.NonPublic);
|
||||||
|
foreach (var field in objFields) // 遍历字段列表,查找需要修改的属性
|
||||||
|
{
|
||||||
|
if (field.Name == $"<{propertyName}>i__Field")
|
||||||
|
{
|
||||||
|
field.SetValue(obj, propertyValue); // 使用反射修改属性值
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
obj.GetType().GetProperty(propertyName).SetValue(obj, propertyValue);
|
||||||
|
}
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
internal static bool IsNumberArray(Type type)
|
internal static bool IsNumberArray(Type type)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user