Exemple #1
0
        protected override Expression VisitExtension(Expression extensionExpression)
        {
            if (extensionExpression is NavigationBindingExpression navigationBindingExpression &&
                navigationBindingExpression.RootParameter == _rootParameter)
            {
                var result = navigationBindingExpression.RootParameter.BuildPropertyAccess(navigationBindingExpression.NavigationTreeNode.ToMapping);

                return(result.Type != navigationBindingExpression.Type
                    ? Expression.Convert(result, navigationBindingExpression.Type)
                    : result);
            }

            if (extensionExpression is CustomRootExpression customRootExpression &&
                customRootExpression.RootParameter == _rootParameter)
            {
                var result = _rootParameter.BuildPropertyAccess(customRootExpression.Mapping);

                return(result.Type != customRootExpression.Type
                    ? Expression.Convert(result, customRootExpression.Type)
                    : result);
            }

            if (extensionExpression is NavigationExpansionRootExpression ||
                extensionExpression is NavigationExpansionExpression ||
                extensionExpression is IncludeExpression)
            {
                var result = new NavigationExpansionReducingVisitor().Visit(extensionExpression);

                return(Visit(result));
            }

            return(base.VisitExtension(extensionExpression));
        }
Exemple #2
0
        protected override Expression VisitExtension(Expression extensionExpression)
        {
            switch (extensionExpression)
            {
            case NavigationBindingExpression navigationBindingExpression
                when navigationBindingExpression.RootParameter == _rootParameter:
            {
                var node        = navigationBindingExpression.NavigationTreeNode;
                var navigations = new List <INavigation>();
                while (node != null)
                {
                    if (node.Navigation != null)
                    {
                        navigations.Add(node.Navigation);
                    }
                    node = node.Parent;
                }

                var result = navigationBindingExpression.RootParameter.BuildPropertyAccess(
                    navigationBindingExpression.NavigationTreeNode.ToMapping,
                    navigations.Count == navigationBindingExpression.NavigationTreeNode.ToMapping.Count ? navigations : null);

                return(result.Type != navigationBindingExpression.Type
                        ? Expression.Convert(result, navigationBindingExpression.Type)
                        : result);
            }

            case CustomRootExpression customRootExpression
                when customRootExpression.RootParameter == _rootParameter:
            {
                var result = _rootParameter.BuildPropertyAccess(customRootExpression.Mapping);

                return(result.Type != customRootExpression.Type
                        ? Expression.Convert(result, customRootExpression.Type)
                        : result);
            }

            case NavigationExpansionRootExpression _:
            case NavigationExpansionExpression _:
            {
                var result = new NavigationExpansionReducingVisitor().Visit(extensionExpression);

                return(Visit(result));
            }

            default:
                return(base.VisitExtension(extensionExpression));
            }
        }