示例#1
0
        /// <summary>
        /// Adds the "out()" step to the traversal, returning all adjacent vertices connected via
        /// outbount edges
        /// </summary>
        /// <typeparam name="S">The source of the traversal</typeparam>
        /// <typeparam name="TVertex">The type of the vertex.</typeparam>
        /// <typeparam name="TinVertex">The type of the "in"/destination vertex.</typeparam>
        /// <param name="traversal">The traversal.</param>
        /// <param name="edgeSelector">The edge selector.</param>
        /// <returns>Returns the resulting traversal</returns>
        public static ISchemaBoundTraversal <S, TinVertex> Out <S, TVertex, TinVertex>(this ISchemaBoundTraversal <S, TVertex> traversal, Expression <Func <TVertex, EdgeBase <TVertex, TinVertex> > > edgeSelector)
            where TVertex : VertexBase
        {
            var labelName = GetLabelName(typeof(TVertex), edgeSelector);

            return(traversal.ToGraphTraversal().Out(labelName).AsSchemaBound <S, TinVertex>());
        }
示例#2
0
        /// <summary>
        /// Adds the "addV()" step to the traversal, creating a new vertex in the graph.
        /// </summary>
        /// <typeparam name="TVertex">The type of the vertex.</typeparam>
        /// <param name="traversal">The traversal.</param>
        /// <returns>Returns the resulting traversal</returns>
        public static ISchemaBoundTraversal <object, TVertex> AddV <TVertex>(this ISchemaBoundTraversal traversal)
            where TVertex : VertexBase
        {
            var label = LabelNameResolver.GetLabelName(typeof(TVertex));

            return(traversal.ToGraphTraversal <object, object>().AddV(label).AsSchemaBound <object, TVertex>());
        }
示例#3
0
        /// <summary>
        /// Adds the "addE()" step to the traversal, creating a new edge in the graph.
        /// </summary>
        /// <typeparam name="TEdge">The type of the edge.</typeparam>
        /// <param name="traversal">The traversal.</param>
        /// <returns>Returns the resulting traversal</returns>
        public static ISchemaBoundTraversal <object, TEdge> AddE <TEdge>(this ISchemaBoundTraversal traversal)
            where TEdge : EdgeBase
        {
            var label = LabelNameResolver.GetLabelName(typeof(TEdge));

            return(traversal.ToGraphTraversal <object, object>().AddE(label).AsSchemaBound <object, TEdge>());
        }
示例#4
0
        /// <summary>
        /// Adds the "outE()" step to the traversal, returning all adjacent outbound edges
        /// </summary>
        /// <typeparam name="S">The source of the traversal</typeparam>
        /// <typeparam name="TVertex">The type of the vertex.</typeparam>
        /// <typeparam name="TEdge">The type of the edge.</typeparam>
        /// <param name="traversal">The traversal.</param>
        /// <param name="edgeSelector">The edge selector.</param>
        /// <returns>Returns the resulting traversal</returns>
        public static ISchemaBoundTraversal <S, TEdge> OutE <S, TVertex, TEdge>(this ISchemaBoundTraversal <S, TVertex> traversal, Expression <Func <TVertex, TEdge> > edgeSelector)
            where TVertex : VertexBase
            where TEdge : IHasOutVertex <TVertex>
        {
            var labelName = LabelNameResolver.GetLabelName(typeof(TEdge));

            return(traversal.ToGraphTraversal().OutE(labelName).AsSchemaBound <S, TEdge>());
        }
示例#5
0
        /// <summary>
        /// Adds the "outE()" step to the traversal, returning all adjacent outbound edges
        /// </summary>
        /// <typeparam name="S">The source of the traversal</typeparam>
        /// <typeparam name="TVertex">The type of the vertex.</typeparam>
        /// <param name="traversal">The traversal.</param>
        /// <param name="edgeSelectors">The edge selectors.</param>
        /// <returns>Returns the resulting traversal</returns>
        public static GraphTraversal <S, Gremlin.Net.Structure.Edge> OutE <S, TVertex>(this ISchemaBoundTraversal <S, TVertex> traversal, params Expression <Func <TVertex, IHasOutVertex <TVertex> > >[] edgeSelectors)
            where TVertex : VertexBase
        {
            if (edgeSelectors == null)
            {
                throw new ArgumentNullException(nameof(edgeSelectors));
            }

            var vertexType = typeof(TVertex);
            var edgeLabels = edgeSelectors.Select(es => GetLabelName(vertexType, es)).ToArray();

            return(traversal.ToGraphTraversal().OutE(edgeLabels));
        }
示例#6
0
        /// <summary>
        /// Adds the "property()" step to the traversal, updating a property on an element
        /// </summary>
        /// <typeparam name="S">The source of the traversal</typeparam>
        /// <typeparam name="TElement">The type of the element.</typeparam>
        /// <typeparam name="TProperty">The type of the property.</typeparam>
        /// <param name="traversal">The traversal.</param>
        /// <param name="propertySelector">The property selector.</param>
        /// <param name="value">The value to set.</param>
        /// <returns>Returns the resulting traversal</returns>
        public static ISchemaBoundTraversal <S, TElement> Property <S, TElement, TProperty>(this ISchemaBoundTraversal <S, TElement> traversal, Expression <Func <TElement, TProperty> > propertySelector, TProperty value)
        {
            var propName = GetPropertyName(typeof(TElement), propertySelector);

            //if the property is an enumerable, we need to specify the cardinality to be list
            if (TYPE_OF_ENUMERABLE.IsAssignableFrom(typeof(TProperty)) && typeof(TProperty) != typeof(string))
            {
                var enumerator = ((IEnumerable)value).GetEnumerator();
                var result     = traversal;
                while (enumerator.MoveNext())
                {
                    result = result.ToGraphTraversal().Property(Cardinality.List, propName, enumerator.Current).AsSchemaBound();
                }
                return(result);
            }
            else
            {
                return(traversal.ToGraphTraversal().Property(propName, value).AsSchemaBound());
            }
        }
示例#7
0
 /// <summary>
 /// Submits the given traversal query to the <see cref="Gremlin.Net.CosmosDb.IGraphClient"/>
 /// and returns the result
 /// </summary>
 /// <typeparam name="S"></typeparam>
 /// <typeparam name="E"></typeparam>
 /// <param name="graphClient">The graph client.</param>
 /// <param name="traversal">The traversal.</param>
 /// <param name="serializerSettings">The serializer settings.</param>
 /// <returns>Returns the result</returns>
 /// <exception cref="ArgumentNullException">traversal</exception>
 public static Task <IReadOnlyCollection <E> > SubmitAsync <S, E>(this IGraphClient graphClient, ISchemaBoundTraversal <S, E> traversal, JsonSerializerSettings serializerSettings)
 {
     return(graphClient.SubmitAsync <E>(traversal.ToGraphTraversal(), serializerSettings));
 }
示例#8
0
        /// <summary>
        /// Adds the "has()" step to the traversal, removing traversers that do not satisfy the given
        /// traversal for the given property
        /// </summary>
        /// <typeparam name="S">The source of the traversal</typeparam>
        /// <typeparam name="TElement">The type of the element.</typeparam>
        /// <typeparam name="TProperty">The type of the property.</typeparam>
        /// <param name="traversal">The traversal.</param>
        /// <param name="propertySelector">The property selector.</param>
        /// <param name="propertyTraversal">The value to compare.</param>
        /// <returns>Returns the resulting traversal</returns>
        public static ISchemaBoundTraversal <S, TElement> Has <S, TElement, TProperty>(this ISchemaBoundTraversal <S, TElement> traversal, Expression <Func <TElement, TProperty> > propertySelector, ITraversal propertyTraversal)
        {
            var propName = GetPropertyName(typeof(TElement), propertySelector);

            return(traversal.ToGraphTraversal().Has(propName, propertyTraversal).AsSchemaBound());
        }
示例#9
0
 /// <summary>
 /// Adds the "outV()" step to the traversal, returning all outbound adjacent vertices
 /// </summary>
 /// <typeparam name="S">The source of the traversal</typeparam>
 /// <typeparam name="ToutVertex">The type of the vertex.</typeparam>
 /// <param name="traversal">The traversal.</param>
 /// <returns>Returns the resulting traversal</returns>
 public static ISchemaBoundTraversal <S, ToutVertex> OutV <S, ToutVertex>(this ISchemaBoundTraversal <S, IHasOutVertex <ToutVertex> > traversal)
 {
     return(traversal.ToGraphTraversal().InV().AsSchemaBound <S, ToutVertex>());
 }