(user:User {userName: " /> (user:User {userName: " /> (user:User {userName: "/>

How do I convert this cypher query to Neo4jClient fluent interface?

112 Views Asked by At

I have this raw query I wish to convert to the fluent interface.

        var assetExistsQuery = new Query(
            @"MATCH (tenant:Tenant)-[r]->(user:User {userName: $userName})
            WHERE tenant.status = $status  AND tenant.userId = $userId
            RETURN user,tenant", new
            {
                userId = params.UserId,
                status = params.TenantStatus,
                userName = params.UserName,
            });

This is what I've got to so far

        var result = await CypherQuery
            .Match("(tenant:Tenant)-[r]->(user:User)")
            .Where((Tenant tenant, User user) => tenant.Status == params.Status && tenant.UserId == params.UserId && user.UserName == params.UserName)
            .Return<Tenant>("tenant").ResultsAsync;

but I am getting this error

System.MissingMethodException: 'Method not found: 'System.Threading.Tasks.Task`1<!!0> Neo4j.Driver.IAsyncSession.ReadTransactionAsync(System.Func`2<Neo4j.Driver.IAsyncTransaction,System.Threading.Tasks.Task`1<!!0>>)'.'

my project uses these packages:

   <PackageReference Include="Neo4j.Driver.Simple.Signed" Version="5.0.0" /> 
    <PackageReference Include="Neo4jClient.DataAnnotations" Version="2.2.4" />
    <PackageReference Include="Neo4jClient.Extension.Attributes.NetStandard" Version="2.0.0" />
    <PackageReference Include="Neo4jClient.Extension.NetStandard" Version="2.0.0" />

Do you know what am I doing wrong here?

1

There are 1 best solutions below

0
Charlotte Skardon On

The Where I think is the problem, please try:

var result = await CypherQuery
    .Match("(tenant: Tenant)-[r]->(user: User)")
    .Where((Tenant tenant) => tenant. Status == params.Status)
    .AndWhere((Tenant tenant) => tenant.UserId == params.UserId)
    .AndWhere((User user) => user.UserName == params.UserName)
    .Return<Tenant>("tenant").ResultsAsync;

You might be able to get away with the two Tenant checks in the same clause, but I suspect not as you need the AND and that comes from the AndWhere bit