Neo4jClient节点ID [英] Neo4jClient node ids

查看:145
本文介绍了Neo4jClient节点ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法确定ID在Neo4jClient中的工作方式.我希望我的.NET模型具有标识符属性,理想情况下,我希望它仅对该节点使用Neo4j自动递增的ID.

I'm having trouble working out how the ID work in Neo4jClient. I want my .NET model to have an identifier property, and ideally I'd like it just to use the Neo4j autoincremented id for that node.

但是,无论我在模型类中使用哪种情况(idIDId),它总是将其添加为Neo4j中的另一个字段(在创建新节点时将其保持为0). .因此,当我在Neo4j浏览器中查看该节点时,它具有一个自动递增的<id>,以及一个我的id字段,该字段始终为0(除非我在C#中的模型中手动设置了该字段).

However, no matter what case I use (id, ID, Id) in my model class, it always adds this as another field in Neo4j (keeping it as 0 when I create a new node). So when I view that node in the Neo4j browser, it has a <id> which is auto-incremented, and also my id field which is always 0 (unless I manually set it in my model in C#).

我希望能够创建一个新的.NET模型类(其初始未初始化ID为0),然后使用Neo4j流利Cypher查询创建它之后,它将具有新创建的.NET模型类的ID.创建的节点的自动递增ID.

I want to be able to create a new .NET model class (which will initially have an uninitialised id of 0), then once I've created it with the Neo4j fluent Cypher query, it will have the ID from the newly created node's autoincremented ID.

此处的示例: https://github.com/Readify/Neo4jClient/wiki/cypher-examples

显示其具有这样ID的User类:

Show their User class of having an ID like this:

public long Id { get; set; }

但是在创建新用户的示例中……

But in the example for creating a new User ...

var newUser = new User { Id = 456, Name = "Jim" };
graphClient.Cypher
    .Create("(user:User {newUser})")
    .WithParam("newUser", newUser)
    .ExecuteWithoutResults();

在这个示例中,我不确定这个456幻数来自何处,但是我只希望它是Neo4j id,在创建它之前,我显然不知道.

I'm unsure where this 456 magic number comes from in this example, but I just want this to be the Neo4j id, which I obviously don't know until it's created.

推荐答案

亚历山德罗(Alessandro)是正确的,并且您不应当然不使用Node ID作为对内部表示的映射.如果要删除一个节点,然后创建另一个节点,则该节点可能具有相同的ID.

Alessandro is correct, and you shouldn't use the Node ID certainly not as maps to internal representations. If you were to delete a node, then create another, it may well have the same ID.

现在,有些时候您需要来获取ID(再次不需要用作内部标识符)-但是可能是在Path结果之类的东西中, Neo4jClient确实允许您获取它.

Now, there are some times you need to get the ID, (again not for use as an internal identifier) - but maybe in a Path result or something, and Neo4jClient does allow you to get it.

被警告,这是龙说谎的方式.

Neo4jClient都是关于POCO的,它可以帮助您将它们转换为Neo4j或从Neo4j转换过来,WIKI的示例仅是一个示例,ID可以来自任何数量的来源,也可以是任何类型,例如例如,我经常使用GUID作为ID.同样,我过去使用过 SnowMaker 之类的东西来生成ID.如果需要节点ID,则需要将POCO包装为Node<T>类型,因此:

Neo4jClient is all about POCO's, it helps you translate them to and from Neo4j, the example from the WIKI is just that, an example, the ID could have come from any number of sources, or be any type, for example, I quite often use GUIDs for my IDs. Equally, I've used things like SnowMaker in the past to generate IDs. If you want the Node ID, you need to wrap your POCO in a Node<T> type, so:

client.Cypher.Match("(n:User)").Return(n => n.As<User>()).Results;

为您提供IEnumerable<User>响应,而:

client.Cypher.Match("(n:User)").Return(n => n.As<Node<User>>()).Results;

为您提供一个IEnumerable<Node<User>>响应,其中Node<T>的每个实例将具有一个属性-Reference,它是Neo4j ID,另一个是-Data,它是T/POCO位.

gets you an IEnumerable<Node<User>> response, where each instance of Node<T> will have a property - Reference which is the Neo4j ID and another - Data which is the T / POCO bit.

这篇关于Neo4jClient节点ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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