Skip to content

How to Retrieve Vertex IDs While Adding Vertices in a Transaction with JanusGraph.Net? #4407

Answered by FlorianHockmann
XM-8JD2 asked this question in Q&A
Discussion options

You must be logged in to vote

You don't need to explicitly handle transactions here. You can simply construct a single traversal that creates your vertices and returns the IDs of the created vertices. JanusGraph Server will automatically execute such a traversal in its own transaction with automatic commit and rollback in case an exception occurs.

This looks something like this in C#:

var t = g.Inject(1); // Inject() is only necessary to get a `GraphTraversal`
foreach (var item in DATA)
{
    t.AddV("DATA").Property(Cardinality.Single, "ID", item).Id().Aggregate("ids");
}
var ids = await t.Cap<List<object>>("ids").Promise(tr => tr.Next());

I used async here to execute the traversal, but you can of course also do it sy…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@XM-8JD2
Comment options

@FlorianHockmann
Comment options

Answer selected by XM-8JD2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants