public static Expression <Func <T1, bool> > GetWhereExpression <T1>(ISelect <T1> select, DynamicFilterInfo filter) { var properties = filter.Field.Split('.'); var tree = TableRefTree.GetTableRefTree(select, properties.Length, properties); // 检索 var treeList = GetTreeList(tree).ToList(); var deepest = treeList.Last(); var collectionNodes = treeList.Where(a => a.TableRef.RefType == TableRefType.OneToMany || a.TableRef.RefType == TableRefType.ManyToMany).ToList(); if (deepest.Level != properties.Length) { throw new Exception($"当前类型{typeof(T1)}导航属性{filter.Field}匹配检索失败"); } if (collectionNodes.Count == 0) { throw new Exception($"当前类型{typeof(T1)}导航属性{filter.Field}不包含{TableRefType.OneToMany}或者{nameof(TableRefType.ManyToMany)}关系"); } var selectMethod = typeof(FreeSqlGlobalExtensions).GetMethods().First(a => a.ContainsGenericParameters && a.GetParameters().Count() == 1); var parameterExpression = Expression.Parameter(typeof(T1), "t"); var manyLevel = 0; var exp = GetWhereExpression(select, deepest, filter, properties, null, ref manyLevel); return(exp as Expression <Func <T1, bool> >); }
public static ISelect <T1> IncludeLevel <T1>(this ISelect <T1> select, int level) { var tree = TableRefTree.GetTableRefTree(select, level); return(select.IncludeLevel(level, tree)); }