简体   繁体   English

在neo4j .net客户端中使用cypher foreach

[英]using cypher foreach In neo4j .net client

I am using neo4j from C# with the Neo4jClient v 1.1.0.34 and would like to use foreach to update a value in multiple noted in C#, I have the following code: 我正在将Neo4jClient v 1.1.0.34与C#中的neo4j配合使用,并想使用foreach更新C#中提到的多个值,我有以下代码:

graphClient.Cypher.Match("(u:User)-[:HAS_EMAIL]->(e:Email)-[:HAS_VER_CODE]->(s:VerCode)"
)
.Where((User u, Email e, VerCode s) => (
       u.id == user.id && e.address == email.address 
       && e.isVerified == false && s.expiry > DateTime.Now))
.Set("s.expiry = {now}")
.WithParam("now", DateTime.Now)
.ExecuteWithoutResults();

As is, the code above is not setting the expiry field on any of the matching nodes. 照原样,上面的代码未在任何匹配节点上设置有效期字段。

I need to set the expiry field to the current date time, but I cannot figure out how to use the .foreach (and have failed to find any examples in C#), the .for each template is give like this: 我需要将到期时间字段设置为当前日期时间,但是我无法弄清楚如何使用.foreach(并且在C#中找不到任何示例),每个模板的.for如下所示:

.foreach (var item in collection){}

Thank you for your time, 感谢您的时间,

Adrian 阿德里安

Sorry - total misunderstanding of your question. 抱歉-对您的问题的完全误解。

Using foreach in Cypher is different to foreach in C# , what you need is a collection of what you're wanting to search through, : 使用foreach在Cypher支架是对不同foreachC# ,你需要的是你想通过搜索,什么样的集合:

public class IdAndEmail { int Id {get;set;} string Address {get;set;} }

var idAndEmails = new List<IdAndEmail>{ new IdAndEmail { Id = 1, Address = "a@b.com"} /*etc*/ };

Once you have that, your cypher becomes: 一旦有了它,您的密码就变成:

graphClient.Cypher.Foreach(idAndEmails, "x")
    .Match("(u:User)-[:HAS_EMAIL]->(e:Email)-[:HAS_VER_CODE]->(s:VerCode)")
    .Where("u.id = x.Id AND e.address = x.Address")
    .AndWhere((Email e, VerCode s) => (e.isVerified == false && s.expiry > DateTime.Now))
    .Set("s.expiry = {now}")
    .WithParam("now", DateTime.Now)
    .ExecuteWithoutResults();

I'm not typing this somewhere I can fully test the code is right, in terms of syntax, but that should get you there. 在语法方面,我没有在可以完全测试代码正确的地方键入此命令,但这应该可以帮助您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM