ra0o0f / arangoclient.net

ArangoDB .NET Client with LINQ support
Apache License 2.0
99 stars 37 forks source link

Question about all path between Vertex A to Vertex B #81

Open biraj01 opened 7 years ago

biraj01 commented 7 years ago

So far works the methods Transversal and ShortestPath perfect, but I cannot find any method to get list of all Paths between Vertex A and Vertex B.

biraj01 commented 7 years ago

After spending fast a day for this simple query, i found a result for it, but is there not any easy method to find all paths between Vertex A and Vertex B? IList par2 = new List(); par2.Add(new QueryParameter() { Name = "P1", Value = startLokation }); par2.Add(new QueryParameter() { Name = "P2", Value = zielLokation }); db.CreateStatement<PathResult<ALokation, ATransportbeziehung>>("for graph_0_target, graph_0_unused, graph_0_Path in 1..6 any @P1 graph \"hls\" filter ( graph_0_target._id == @P2 ) return graph_0_Path", par2);

ra0o0f commented 7 years ago

@biraj01 if you mean this example. it can be written in LINQ

public class EdgeCollection
{
    [DocumentProperty(Identifier = IdentifierType.Key)]
    public string Key { get; set; }
}

public class VertexCollection
{
    [DocumentProperty(Identifier = IdentifierType.Key)]
    public string Key { get; set; }
}

var result = db.Query()
    .Traversal<VertexCollection, EdgeCollection>("from-vertex")
    .Depth(0, 5)
    .AnyDirection()
    .Graph("graph-name")
    .Where(x => x.Vertex.Key == "to-vert")
    .Select(x => x.Path)
    //.ToList()
    .GetQueryData();

Console.WriteLine(result.QueryReplacedWithVariables(db));
// will print
//for `graph_0_Vertex`, `graph_0_Edge`, `graph_0_Path` in  0..5  any  "from-vertex"   graph "graph-name"
//filter  ( `graph_0_Vertex`.`_key`  ==  "to-vert"  )
//return  `graph_0_Path`
biraj01 commented 7 years ago

You have a filter matching any vertex of graph to "to-vert"
filter ( graph_0_Vertex._key == "to-vert" )
But my query is to filter every path which target is equal to "to-vert" filter ( graph_0_target._id == "to-vert")

ra0o0f commented 7 years ago

@biraj01 graph_0_Vertex is same as graph_0_target, both are target vertices in traversal.