I know this is old, but the way I implement it is like this:
var result = await _session.RunAsync("MATCH (u:User) RETURN u");
return await result.ToListAsync(record =>
{
var node = record["u"].As<INode>();
return JsonSerializer.Deserialize<User>(
JsonSerializer.Serialize(node.Properties)
) ?? new User();
});
You could also write an extension method on INode for something like this:
public static T ToObject<T>(this INode node)
{
return System.Text.Json.JsonSerializer.Deserialize<T>(
System.Text.Json.JsonSerializer.Serialize(node.Properties)
) ?? default;
}
Then, you just call it like this:
var node = record[0].As<INode>();
var user = node.ToObject<User>();