/// <summary> /// Adds the segment as pathedgenode /// </summary> /// <param name="parentNode">The parent node.</param> /// <param name="segments">The segments.</param> /// <param name="currentNodeIndex">The current node index in the segments list.</param> /// <param name="pathElement">The path element.</param> /// <param name="entityType">Type of the entity.</param> /// <remarks>Declared public to avoid medium trust reflection issues.</remarks> public void AddSegment(PathEdgeNode parentNode, IList <ExpandSegment> segments, int currentNodeIndex, IPrefetchPathElementCore pathElement, Type entityType) { if (currentNodeIndex >= segments.Count) { return; } ExpandSegment segment = segments[currentNodeIndex]; PathEdgeNode childNode = null; if (!parentNode.ChildPathEdgeNodes.TryGetValue(segment.Name, out childNode)) { childNode = new PathEdgeNode(entityType, pathElement, segment); parentNode.ChildPathEdgeNodes.Add(segment.Name, childNode); } DecodeSegment(childNode, segments, ++currentNodeIndex, entityType); }
/// <summary> /// Applies expansions to the specified <paramref name="query"/> parameter. /// </summary> /// <param name="query">The <see cref="T:System.Linq.IQueryable`1"/> object to expand.</param> /// <param name="expandPaths">A collection of <see cref="T:System.Data.Services.ExpandSegmentCollection"/> paths to expand.</param> /// <returns></returns> public IEnumerable ApplyExpansions(IQueryable query, ICollection <ExpandSegmentCollection> expandPaths) { if ((query == null) || !typeof(IEntityCore).IsAssignableFrom(query.ElementType)) { // not an entity query, expansions are not doable. return(query); } var rootNode = new PathEdgeNode(); foreach (ExpandSegmentCollection expandSegments in expandPaths) { DecodeSegment(rootNode, expandSegments, 0, query.ElementType); } IPathEdge[] rootPathEdges = rootNode.GetChildPathEdges(); return(typeof(LLBLGenProODataServiceExpandProvider).GetMethod("AppendWithPathCall", BindingFlags.Public | BindingFlags.Static) .MakeGenericMethod(query.ElementType) .Invoke(null, new object[] { query, rootPathEdges }) as IEnumerable); }
/// <summary> /// Decodes an expansion segment. /// </summary> /// <param name="parentNode">The parent node.</param> /// <param name="segments">The segments.</param> /// <param name="currentNodeIndex">The current node index in the segments list.</param> /// <param name="entityType">Type of the entity.</param> private void DecodeSegment(PathEdgeNode parentNode, IList <ExpandSegment> segments, int currentNodeIndex, Type entityType) { if (currentNodeIndex >= segments.Count) { return; } var navigatorProperty = entityType.GetProperty(segments[currentNodeIndex].Name); if (navigatorProperty == null) { return; } Type navigatorEntityType = typeof(IEntityCore).IsAssignableFrom(navigatorProperty.PropertyType) ? navigatorProperty.PropertyType : navigatorProperty.PropertyType.BaseType.GetGenericArguments()[0]; PropertyInfo prefetchPathProperty = entityType.GetProperty("PrefetchPath" + segments[currentNodeIndex].Name, BindingFlags.Static | BindingFlags.Public); IPrefetchPathElementCore prefetchPathElement = prefetchPathProperty.GetValue(null, null) as IPrefetchPathElementCore; AddSegment(parentNode, segments, currentNodeIndex, prefetchPathElement, navigatorEntityType); }