Ejemplo n.º 1
0
 public static void CopyIncludeInformation(NavigationTreeNode originalNavigationTree, NavigationTreeNode newNavigationTree, SourceMapping newSourceMapping)
 {
     foreach (var child in originalNavigationTree.Children.Where(n => n.IncludeState == NavigationState.Pending))
     {
         var copy = NavigationTreeNode.Create(newSourceMapping, child.Navigation, newNavigationTree, true);
         CopyIncludeInformation(child, copy, newSourceMapping);
     }
 }
Ejemplo n.º 2
0
        private Expression TryBindProperty(Expression originalExpression, Expression newExpression, string navigationMemberName)
        {
            if (newExpression is NavigationBindingExpression navigationBindingExpression)
            {
                if (navigationBindingExpression.RootParameter == _rootParameter)
                {
                    var navigation = navigationBindingExpression.EntityType.FindNavigation(navigationMemberName);
                    if (navigation != null)
                    {
                        var navigationTreeNode = NavigationTreeNode.Create(
                            navigationBindingExpression.SourceMapping, navigation, navigationBindingExpression.NavigationTreeNode, _bindInclude);

                        return(new NavigationBindingExpression(
                                   navigationBindingExpression.RootParameter,
                                   navigationTreeNode,
                                   navigation.GetTargetType(),
                                   navigationBindingExpression.SourceMapping,
                                   originalExpression.Type));
                    }
                }
            }
            else
            {
                foreach (var sourceMapping in _sourceMappings)
                {
                    var candidates = sourceMapping.NavigationTree.Flatten()
                                     .SelectMany(n => n.FromMappings, (n, m) => (navigationTreeNode: n, path: m)).ToList();
                    var match = TryFindMatchingNavigationTreeNode(originalExpression, candidates);
                    if (match.navigationTreeNode != null)
                    {
                        return(new NavigationBindingExpression(
                                   match.rootParameter,
                                   match.navigationTreeNode,
                                   match.navigationTreeNode.Navigation?.GetTargetType() ?? sourceMapping.RootEntityType,
                                   sourceMapping,
                                   originalExpression.Type));
                    }
                }
            }

            return(null);
        }