3

Currently, with a single traversal, I can either do:

Edge edge = g.E().Next();
var inv = edge.InV;
var outv = edge.OutV;
var id = edge.Id;

which allows me to get an edge's id, as well as the ids of the vertices the edge goes between. Or, I could do:

IDictionary<object, object> dict = g.E().ValueMap<object, object>(true).Next();
var id = dict[T.id]
var edgeProp = dict["$edgePropertyName"];

which allows me to get properties and the id, but not the ids of the edges. Is there a way to get both the vertices and the properties in a single traversal?

Samuel Barr
  • 434
  • 4
  • 12

2 Answers2

5

Sure, just use project():

gremlin> g.E().
......1>   project('id','properties','out','in').
......2>     by(id).
......3>     by(valueMap()).
......4>     by(outV().id()).
......5>     by(inV().id())
==>[id:7,properties:[weight:0.5],out:1,in:2]
==>[id:8,properties:[weight:1.0],out:1,in:4]
==>[id:9,properties:[weight:0.4],out:1,in:3]
==>[id:10,properties:[weight:1.0],out:4,in:5]
==>[id:11,properties:[weight:0.4],out:4,in:3]
==>[id:12,properties:[weight:0.2],out:6,in:3]
stephen mallette
  • 45,298
  • 5
  • 67
  • 135
  • This is it- thanks! (For specifically using this solution in Gremlin.Net, use the __ class for the anonymous traversals) – Samuel Barr Aug 16 '18 at 16:52
3

Translation of the accepted answer into C#:

var result = g.E()
    .Project<object>("id", "properties", "out", "in")
    .By(__.Id())
    .By(__.ValueMap<string, object>())
    .By(__.OutV().Id())
    .By(__.InV().Id())
    .Next();
Samuel Barr
  • 434
  • 4
  • 12