在 Neo4j .net 客户端中使用 cypher foreach [英] using cypher foreach In neo4j .net client

查看:110
本文介绍了在 Neo4j .net 客户端中使用 cypher foreach的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用来自 C# 的 Neo4j 和 Neo4jClient v 1.1.0.34,并想使用 foreach 来更新 C# 中记录的多个值,我有以下代码:

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:

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.

我需要将到期字段设置为当前日期时间,但我不知道如何使用 .foreach(并且未能在 C# 中找到任何示例),每个模板的 .for 如下所示:

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 (var item in collection){}

感谢您的时间,

阿德里安

推荐答案

抱歉 - 完全误解了您的问题.

Sorry - total misunderstanding of your question.

在 Cypher 中使用 foreachC# 中的 foreach 不同,你需要的是你想要搜索的集合,:

Using foreach in Cypher is different to foreach in C#, what you need is a collection of what you're wanting to search through, :

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.

这篇关于在 Neo4j .net 客户端中使用 cypher foreach的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆