首页 > 解决方案 > 如何在 Cypher Query 的 where IN 子句中使用 int[](使用 C#)

问题描述

我有这个密码查询

int[] pIds = new int[] {101, 012}; 
var query = _graphClient.Cypher.Read
            .OptionalMatch($"(p: {Labels.PERSON})")
            .Where($"p.Id IN [{pIds}]") 
            .Return<Person>(p);

在调试时它看起来像这样:

OPTIONAL MATCH (p: Person)
WHERE p.Id IN [System.Int32[]] 
RETURN distinct p

我应该在这个 where 子句 [101, 012] 中传递的值,但不是。因为 pIds[0] = 101,pIds[1] = 012 - 并且它从未在密码查询中读取。

我在哪里出错并且未能传递价值观?我应该如何在 Where IN... 中传递 int[]

标签: c#neo4jcypher

解决方案


最好的可能是使用参数:

int[] pIds = new int[] {101, 012}; 
var query = _graphClient.Cypher.Read
            .OptionalMatch($"(p: {Labels.PERSON})")
            .Where($"p.Id IN $pIds") 
            .Return<Person>(p)
            .WithParam("pIds", pIds);

推荐阅读