Transaction on Graph Cosmos DB

Viewed 2060

I have two queries in gremlin which first one is adding a vertex, and the second one is adding an edge between the added vertex and an existed vertex in the graph.

string query1 = $"g.addV('session').property('id','{session_id}').property('initialState', 'start')";
string query2 = $"g.V('{session_id}').addE('belongs').to(g.V('{userId}'))";

As I wrote the program in C#, the first idea to be sure both of the above commands run or neither of them, is using TransactionScope in C#. However, it is not solved my problem as it is not on Cosmos DB. The question is how can I do these commands in a transaction on Graph Cosmos DB in C#?.

Is there any technique to resolve this in gremlin? Is graph.tx().commit() works on Cosmos DB?

// In A Transaction Scope
IDocumentQuery<dynamic> query = database.Client.CreateGremlinQuery<dynamic>(database.Graph, query1);
query.ExecuteNextAsync().Result;

query = database.Client.CreateGremlinQuery<dynamic>(database.Graph, query2);
query.ExecuteNextAsync().Result;
2 Answers
Related