private static KeyValuePair <String, Object>[] GetNavigationSkipTokenKeys(OeEntryFactory entryFactory, OrderByClause orderByClause, Object value) { IEdmStructuralProperty[] keyProperties = OeSkipTokenParser.GetEdmProperies(orderByClause); var keys = new KeyValuePair <String, Object> [keyProperties.Length]; for (int i = 0; i < keys.Length; i++) { String propertyName = OeSkipTokenParser.GetPropertyName(keyProperties[i]); OePropertyAccessor accessor = entryFactory.GetAccessorByName(keyProperties[i].Name); keys[i] = new KeyValuePair <String, Object>(propertyName, accessor.GetValue(value)); } return(keys); }
private static Uri BuildNavigationNextPageLink(OeEntryFactory entryFactory, ExpandedNavigationSelectItem expandedNavigationSelectItem, Object value) { var segment = (NavigationPropertySegment)expandedNavigationSelectItem.PathToNavigationProperty.LastSegment; IEdmNavigationProperty navigationProperty = segment.NavigationProperty; if (navigationProperty.IsPrincipal()) { navigationProperty = navigationProperty.Partner; } var keys = new List <KeyValuePair <IEdmStructuralProperty, Object> >(); IEnumerator <IEdmStructuralProperty> dependentProperties = navigationProperty.DependentProperties().GetEnumerator(); foreach (IEdmStructuralProperty key in navigationProperty.PrincipalProperties()) { dependentProperties.MoveNext(); Object keyValue = entryFactory.GetAccessorByName(key.Name).GetValue(value); keys.Add(new KeyValuePair <IEdmStructuralProperty, Object>(dependentProperties.Current, keyValue)); } ResourceRangeVariableReferenceNode refNode = OeEdmClrHelper.CreateRangeVariableReferenceNode((IEdmEntitySet)segment.NavigationSource); BinaryOperatorNode filterExpression = OeGetParser.CreateFilterExpression(refNode, keys); if (expandedNavigationSelectItem.FilterOption != null) { filterExpression = new BinaryOperatorNode(BinaryOperatorKind.And, filterExpression, expandedNavigationSelectItem.FilterOption.Expression); } var segments = new ODataPathSegment[] { new EntitySetSegment((IEdmEntitySet)refNode.NavigationSource) }; var odataUri = new ODataUri() { Path = new ODataPath(segments), Filter = new FilterClause(filterExpression, refNode.RangeVariable), OrderBy = expandedNavigationSelectItem.OrderByOption, SelectAndExpand = expandedNavigationSelectItem.SelectAndExpand, Top = expandedNavigationSelectItem.TopOption, Skip = expandedNavigationSelectItem.SkipOption, QueryCount = expandedNavigationSelectItem.CountOption }; return(odataUri.BuildUri(ODataUrlKeyDelimiter.Parentheses)); }
private static FilterClause?GetFilter(IEdmModel edmModel, OeEntryFactory entryFactory, ExpandedNavigationSelectItem item, Object value) { SingleValueNode filterExpression; ResourceRangeVariableReferenceNode refNode; var segment = (NavigationPropertySegment)item.PathToNavigationProperty.LastSegment; IEdmNavigationProperty navigationProperty = segment.NavigationProperty; if (navigationProperty.ContainsTarget) { ModelBuilder.ManyToManyJoinDescription joinDescription = edmModel.GetManyToManyJoinDescription(navigationProperty); navigationProperty = joinDescription.JoinNavigationProperty.Partner; IEdmEntitySet joinNavigationSource = OeEdmClrHelper.GetEntitySet(edmModel, joinDescription.JoinNavigationProperty); ResourceRangeVariableReferenceNode joinRefNode = OeEdmClrHelper.CreateRangeVariableReferenceNode(joinNavigationSource, "d"); IEdmEntitySet targetNavigationSource = OeEdmClrHelper.GetEntitySet(edmModel, joinDescription.TargetNavigationProperty); ResourceRangeVariableReferenceNode targetRefNode = OeEdmClrHelper.CreateRangeVariableReferenceNode(targetNavigationSource); var anyNode = new AnyNode(new Collection <RangeVariable>() { joinRefNode.RangeVariable, targetRefNode.RangeVariable }, joinRefNode.RangeVariable) { Source = new CollectionNavigationNode(targetRefNode, joinDescription.TargetNavigationProperty.Partner, null), Body = OeExpressionHelper.CreateFilterExpression(joinRefNode, GetKeys(navigationProperty.PrincipalProperties(), navigationProperty.DependentProperties())) }; refNode = targetRefNode; filterExpression = anyNode; } else { IEnumerable <IEdmStructuralProperty> parentKeys; IEnumerable <IEdmStructuralProperty> childKeys; if (navigationProperty.IsPrincipal()) { parentKeys = navigationProperty.Partner.PrincipalProperties(); childKeys = navigationProperty.Partner.DependentProperties(); } else { if (navigationProperty.Type.IsCollection()) { parentKeys = navigationProperty.PrincipalProperties(); childKeys = navigationProperty.DependentProperties(); } else { parentKeys = navigationProperty.DependentProperties(); childKeys = navigationProperty.PrincipalProperties(); } } refNode = OeEdmClrHelper.CreateRangeVariableReferenceNode((IEdmEntitySetBase)segment.NavigationSource); List <KeyValuePair <IEdmStructuralProperty, Object> > keys = GetKeys(parentKeys, childKeys); if (IsNullKeys(keys)) { return(null); } filterExpression = OeExpressionHelper.CreateFilterExpression(refNode, keys); } if (item.FilterOption != null) { filterExpression = new BinaryOperatorNode(BinaryOperatorKind.And, filterExpression, item.FilterOption.Expression); } return(new FilterClause(filterExpression, refNode.RangeVariable)); List <KeyValuePair <IEdmStructuralProperty, Object> > GetKeys(IEnumerable <IEdmStructuralProperty> parentKeys, IEnumerable <IEdmStructuralProperty> childKeys) { var keys = new List <KeyValuePair <IEdmStructuralProperty, Object> >(); IEnumerator <IEdmStructuralProperty> childKeyEnumerator = childKeys.GetEnumerator(); foreach (IEdmStructuralProperty parentKey in parentKeys) { childKeyEnumerator.MoveNext(); Object keyValue = entryFactory.GetAccessorByName(parentKey.Name).GetValue(value); keys.Add(new KeyValuePair <IEdmStructuralProperty, Object>(childKeyEnumerator.Current, keyValue)); } return(keys); }
private static Uri BuildNavigationNextPageLink(IEdmModel edmModel, OeEntryFactory entryFactory, ExpandedNavigationSelectItem expandedNavigationSelectItem, Object value) { SingleValueNode filterExpression; ResourceRangeVariableReferenceNode refNode; var segment = (NavigationPropertySegment)expandedNavigationSelectItem.PathToNavigationProperty.LastSegment; IEdmNavigationProperty navigationProperty = segment.NavigationProperty; if (navigationProperty.ContainsTarget) { ModelBuilder.ManyToManyJoinDescription joinDescription = edmModel.GetManyToManyJoinDescription(navigationProperty); navigationProperty = joinDescription.JoinNavigationProperty.Partner; IEdmEntitySet joinNavigationSource = OeEdmClrHelper.GetEntitySet(edmModel, joinDescription.JoinNavigationProperty); ResourceRangeVariableReferenceNode joinRefNode = OeEdmClrHelper.CreateRangeVariableReferenceNode(joinNavigationSource, "d"); IEdmEntitySet targetNavigationSource = OeEdmClrHelper.GetEntitySet(edmModel, joinDescription.TargetNavigationProperty); ResourceRangeVariableReferenceNode targetRefNode = OeEdmClrHelper.CreateRangeVariableReferenceNode(targetNavigationSource); var anyNode = new AnyNode(new Collection <RangeVariable>() { joinRefNode.RangeVariable, targetRefNode.RangeVariable }, joinRefNode.RangeVariable) { Source = new CollectionNavigationNode(targetRefNode, joinDescription.TargetNavigationProperty.Partner, null), Body = OeGetParser.CreateFilterExpression(joinRefNode, GetKeys(navigationProperty)) }; refNode = targetRefNode; filterExpression = anyNode; } else { if (navigationProperty.IsPrincipal()) { navigationProperty = navigationProperty.Partner; } refNode = OeEdmClrHelper.CreateRangeVariableReferenceNode((IEdmEntitySetBase)segment.NavigationSource); filterExpression = OeGetParser.CreateFilterExpression(refNode, GetKeys(navigationProperty)); } if (expandedNavigationSelectItem.FilterOption != null) { filterExpression = new BinaryOperatorNode(BinaryOperatorKind.And, filterExpression, expandedNavigationSelectItem.FilterOption.Expression); } var pathSegments = new ODataPathSegment[] { new EntitySetSegment((IEdmEntitySet)refNode.NavigationSource) }; var odataUri = new ODataUri() { Path = new ODataPath(pathSegments), Filter = new FilterClause(filterExpression, refNode.RangeVariable), OrderBy = expandedNavigationSelectItem.OrderByOption, SelectAndExpand = expandedNavigationSelectItem.SelectAndExpand, Top = expandedNavigationSelectItem.TopOption, Skip = expandedNavigationSelectItem.SkipOption, QueryCount = expandedNavigationSelectItem.CountOption }; return(odataUri.BuildUri(ODataUrlKeyDelimiter.Parentheses)); List <KeyValuePair <IEdmStructuralProperty, Object> > GetKeys(IEdmNavigationProperty edmNavigationProperty) { var keys = new List <KeyValuePair <IEdmStructuralProperty, Object> >(); IEnumerator <IEdmStructuralProperty> dependentProperties = edmNavigationProperty.DependentProperties().GetEnumerator(); foreach (IEdmStructuralProperty key in edmNavigationProperty.PrincipalProperties()) { dependentProperties.MoveNext(); Object keyValue = entryFactory.GetAccessorByName(key.Name).GetValue(value); keys.Add(new KeyValuePair <IEdmStructuralProperty, Object>(dependentProperties.Current, keyValue)); } return(keys); } }