[英]How do I write this in Neo4jClient
Thanks to Dave Bennett, I have a great Neo4j query that provides the results I need. 多亏了Dave Bennett,我有了一个很棒的Neo4j查询,可以提供我需要的结果。 I need to get this to work in Neo4JClient. 我需要让它在Neo4JClient中工作。 Here's my working Neo4j query: 这是我正在工作的Neo4j查询:
`// Composite Tile with related users
match (t:Tile{summary:"Test 1"})<-[:ASSIGNED_TO]-(u:User)
with {summary: t.summary,
id: t.id,
sprint_id: t.sprint_id,
size: t.size,
percent_done: t.percent_done,
color: t.color_id,
description: t.description,
queue_id: t.queue_id,
swimlane_id: t.swimlane_id,
icons: t.icons,
order: t.order,
assignees: collect(u)} as tile
RETURN collect(tile) as tiles`
Visual Studio and/or Neo4jClient is not very happy with my attempt: Visual Studio和/或Neo4jClient对我的尝试不是很满意:
var compositeTile = client.Cypher
.Match("(t:Tile)<-[:ASSIGNED_TO]-(u:User)")
.Where((Tile t)=> t.summary == tile.summary)
.With( {
summary: t.summary,
id: t.id,
sprint_id: t.sprint_id,
size: t.size,
percent_done: tile.percent_done,
color: t.color,
description: t.description,
queue_id: t.queue_id,
swimlane_id: t.swimlane_id,
icons: t.icons,
Order: t.order,
assignees: collect(u)
} as tile)
.return collect(tile) as tiles;
It just throws lots of red squiggly lines, I suspect because I'm not formatting the .with statement correctly. 我怀疑这只是抛出很多红色的波浪线,因为我没有正确格式化.with语句。 I haven't been able to find an example, so I'm asking here. 我还没有找到一个例子,所以我在这里问。 How do I do this correctly in Neo4jClient? 如何在Neo4jClient中正确执行此操作?
So, two answers to your question - the first is that the .With
statement takes a string as a parameter, so you just need to wrap your text with "
(or @"
if you want to keep the formatting). 因此,对于您的问题有两个答案-第一个是.With
语句将字符串作为参数,因此,您只需要用"
(或@"
换行)即可保留文本格式。 The second answer is more of a problem for you though: 第二个答案对您来说更是一个问题:
It's not possible to do what you're trying to do with Neo4jClient
- at the moment it doesn't allow you to create anonymous types. 无法使用Neo4jClient
做您想做的Neo4jClient
-目前,它不允许您创建匿名类型。 It's not able to deserialize the content. 它无法反序列化内容。 I thought it might be a quick fix, but it seems like it would be more involved. 我认为这可能是一个快速解决方案,但似乎会涉及更多问题。 So, what we're looking at here is a change of the query. 因此,我们在这里查看的是查询的更改。
I presume you have a class called Tile
with the properties you're after. 我假设您有一个名为Tile
的类,其中包含您要使用的属性。 So I would change the query to something like this: 因此, 我将查询更改为以下内容:
client.Cypher
.Match("(t:Tile)<-[:ASSIGNED_TO]-(u:User)")
.Where((Tile t) => t.summary == tile.summary)
.Return((t,u) => new {
Tile = t.As<Tile>(),
User = u.CollectAs<User>()
});
Which will give you a C# anonymous type with a Tile and an IEnumerable<Node<User>>
elements, obviously you want the Users
in your Tile
, so you can then parse the result: 这将为您提供一个带有Tile和IEnumerable<Node<User>>
元素的C#匿名类型,显然您希望在Tile
使用Users
,因此可以解析结果:
var tiles = new List<Tile>();
foreach (var result in results)
{
var tile = result.Tile;
foreach (var user in result.Users)
tile.users.Add(user.Data);
tiles.Add(tile);
}
One thing you might find is that you need to initialize the Users
collection, so either add Users = new List<User>()
to your Tile
constructor, or just before parsing the data. 您可能会发现的一件事是,您需要初始化Users
集合,因此可以将Users = new List<User>()
到Tile
构造函数中,或者仅在解析数据之前。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.