public Expression ApplyNavigation(Expression source, IEnumerable <OeParseNavigationSegment> parseNavigationSegments) { if (parseNavigationSegments == null) { return(source); } Type sourceItemType = OeExpressionHelper.GetCollectionItemType(source.Type); foreach (OeParseNavigationSegment parseNavigationSegment in parseNavigationSegments) { Type selectType; ParameterExpression parameter; Expression e; if (parseNavigationSegment.NavigationSegment == null) //EntitySetSegment { parameter = Parameter; e = source; selectType = sourceItemType; } else { parameter = Expression.Parameter(sourceItemType); PropertyInfo navigationClrProperty = sourceItemType.GetTypeInfo().GetProperty(parseNavigationSegment.NavigationSegment.NavigationProperty.Name); e = Expression.MakeMemberAccess(parameter, navigationClrProperty); MethodInfo selectMethodInfo; selectType = OeExpressionHelper.GetCollectionItemType(e.Type); if (selectType == null) { selectType = e.Type; selectMethodInfo = OeMethodInfoHelper.GetSelectMethodInfo(sourceItemType, selectType); } else { selectMethodInfo = OeMethodInfoHelper.GetSelectManyMethodInfo(sourceItemType, selectType); } LambdaExpression lambda = Expression.Lambda(e, parameter); source = Expression.Call(selectMethodInfo, source, lambda); } if (parseNavigationSegment.Filter != null) { var visitor = new OeQueryNodeVisitor(_visitor, Expression.Parameter(selectType)); e = visitor.TranslateNode(parseNavigationSegment.Filter.Expression); LambdaExpression lambda = Expression.Lambda(e, visitor.Parameter); MethodInfo whereMethodInfo = OeMethodInfoHelper.GetWhereMethodInfo(selectType); source = Expression.Call(whereMethodInfo, source, lambda); } _entityType = selectType; sourceItemType = selectType; } _visitor = new OeQueryNodeVisitor(_model, Expression.Parameter(_entityType), _visitor.Constans); return(source); }
public Expression ApplyNavigation(Expression source, IReadOnlyList <OeParseNavigationSegment> parseNavigationSegments) { if (parseNavigationSegments == null) { return(source); } Type sourceItemType = OeExpressionHelper.GetCollectionItemType(source.Type); foreach (OeParseNavigationSegment parseNavigationSegment in parseNavigationSegments) { Type selectType; ParameterExpression parameter; Expression e; if (parseNavigationSegment.NavigationSegment == null) //EntitySetSegment, KeySegment { parameter = Visitor.Parameter; e = source; selectType = sourceItemType; } else { parameter = Expression.Parameter(sourceItemType); PropertyInfo navigationClrProperty = sourceItemType.GetPropertyIgnoreCase(parseNavigationSegment.NavigationSegment.NavigationProperty); e = Expression.MakeMemberAccess(parameter, navigationClrProperty); MethodInfo selectMethodInfo; selectType = OeExpressionHelper.GetCollectionItemTypeOrNull(e.Type) ?? e.Type; if (selectType == e.Type) { selectMethodInfo = OeMethodInfoHelper.GetSelectMethodInfo(sourceItemType, selectType); } else { selectMethodInfo = OeMethodInfoHelper.GetSelectManyMethodInfo(sourceItemType, selectType); } LambdaExpression lambda = Expression.Lambda(e, parameter); source = Expression.Call(selectMethodInfo, source, lambda); } if (parseNavigationSegment.Filter != null) { var visitor = new OeQueryNodeVisitor(Visitor, Expression.Parameter(selectType)); e = visitor.TranslateNode(parseNavigationSegment.Filter.Expression); LambdaExpression lambda = Expression.Lambda(e, visitor.Parameter); MethodInfo whereMethodInfo = OeMethodInfoHelper.GetWhereMethodInfo(selectType); source = Expression.Call(whereMethodInfo, source, lambda); } sourceItemType = selectType; } Visitor.ChangeParameterType(Expression.Parameter(sourceItemType)); return(source); }