mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-12-02 03:13:58 +08:00
db.Queryable.Includes.Select.ToList
This commit is contained in:
@@ -1,12 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
internal class AppendNavInfo
|
||||
{
|
||||
public Dictionary<string, string> MappingNavProperties = new Dictionary<string, string>();
|
||||
public Dictionary<string, MappingNavColumnInfo> MappingNavProperties = new Dictionary<string, MappingNavColumnInfo>();
|
||||
public Dictionary<string, string> AppendProperties = new Dictionary<string, string>();
|
||||
}
|
||||
internal class MappingNavColumnInfo
|
||||
{
|
||||
public List<Expression> ExpressionList { get; set; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -579,6 +579,21 @@ namespace SqlSugar
|
||||
foreach (var item in dic)
|
||||
{
|
||||
var value=item.Value;
|
||||
var expressionTree = new ExpressionTreeVisitor().GetExpressions(value);
|
||||
if (expressionTree.Any())
|
||||
{
|
||||
var name = ExpressionTool.GetMemberName(expressionTree.First());
|
||||
if (name !=null&& entityColumns.Any(it=>it.Navigat!=null&&it.PropertyName==name))
|
||||
{
|
||||
var mappingNavColumnInfo = new MappingNavColumnInfo()
|
||||
{
|
||||
ExpressionList= expressionTree ,
|
||||
Name=name
|
||||
};
|
||||
navInfo.MappingNavProperties.Add(item.Key,mappingNavColumnInfo);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
foreach (var item in navManages)
|
||||
{
|
||||
|
||||
@@ -45,4 +45,46 @@ namespace SqlSugar
|
||||
return base.VisitMethodCall(node);
|
||||
}
|
||||
}
|
||||
|
||||
internal class ExpressionTreeVisitor : ExpressionVisitor
|
||||
{
|
||||
private readonly List<Expression> _nodes = new List<Expression>();
|
||||
//protected override Expression VisitBinary(BinaryExpression node)
|
||||
//{
|
||||
// // 解析二元操作符表达式
|
||||
// _nodes.Add(node);
|
||||
// Visit(node.Left);
|
||||
// Visit(node.Right);
|
||||
// return node;
|
||||
//}
|
||||
//protected override Expression VisitConstant(ConstantExpression node)
|
||||
//{
|
||||
// // 解析常量表达式
|
||||
// _nodes.Add(node);
|
||||
// return node;
|
||||
//}
|
||||
protected override Expression VisitMember(MemberExpression node)
|
||||
{
|
||||
// 解析成员访问表达式
|
||||
_nodes.Add(node);
|
||||
return node;
|
||||
}
|
||||
protected override Expression VisitMethodCall(MethodCallExpression node)
|
||||
{
|
||||
// 解析方法调用表达式
|
||||
_nodes.Add(node);
|
||||
if (node.Arguments.Any())
|
||||
{
|
||||
Visit(node.Arguments.First());
|
||||
}
|
||||
return node;
|
||||
}
|
||||
public List<Expression> GetExpressions(Expression expression)
|
||||
{
|
||||
Visit(expression);
|
||||
_nodes.Reverse();
|
||||
return _nodes;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user