What is the correct way of executing a Cypher query from .NET?
After reading multiple forums and blog posts, I came to the following approach as "the" correct way.
var driver = GraphDatabase.Driver(getUri(), AuthTokens.Basic("username", "password"));
using var session = driver.AsyncSession(x => x.WithDefaultAccessMode(AccessMode.Write));
var queryResult = await session.ExecuteWriteAsync(async x =>
{
IResultCursor cursor = await x.RunAsync(GetQuery());
return await cursor.ToListAsync();
});
This approach works; however, if an error occurs executing the query, the program "halts" with no exceptions thrown.
I tried the following, but even in this case, no exception is caught if an error occurs executing the query.
var queryResult = await session.ExecuteWriteAsync(async x =>
{
try
{
IResultCursor cursor = await x.RunAsync(GetQuery());
return await cursor.ToListAsync();
}
catch(Exception e)
{ }
});