如何在 Cypher 查询中的 where IN 子句中使用 int[](使用 C#)

How to use the int[] in where IN clause in Cypher Query (using 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[]

最好是使用参数:

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);

我通过将 int[] 放入一个由 ,

分隔的字符串中解决了这个问题
var param = string.Join(",", myIntList); 

var query = _graphClient.Cypher.Read
            .OptionalMatch($"(p: {Labels.PERSON})")
            .Where($"p.Id IN $param") 
            .Return<Person>(p)
            .WithParam("param", param)