- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的持久层基本上使用 Neo4jClient 来访问 Neo4j 1.9.4 数据库。更具体地说,为了创建节点,我在 Neo4jClient 的 CRUD API 中使用了 IGraphClient#Create()
,为了查询图表,我使用了 Neo4jClient 的 Cypher 支持。
一切都很好,直到我的一个 friend 指出对于每个查询,我基本上都执行了两个 HTTP 请求:
对于读取 操作,我做了显而易见的事情并将索引查找移动到我的Start()
调用中,即:
GraphClient.Cypher
.Start(new { user = Node.ByIndexLookup("User", "Id", userId) })
// ... the rest of the query ...
另一方面,对于创建 操作,我认为这实际上是不可能的。我的意思是:Create()
方法需要一个 POCO、几个关系实例和几个索引条目,以便在一个事务/HTTP 中创建一个节点、它的关系和它的索引条目要求。问题是您传递给关系实例的节点引用:它们来自哪里?来自以前的 HTTP 请求,对吧?
我的问题:
此外,能否更新 Neo4jClient 的文档,因为坦率地说,它很差。我确实意识到 Readify 还提供商业支持,因此可以解释一些事情。
谢谢!
最佳答案
我是 Neo4jClient 的作者。 (免费赠送软件的人。)
问题 1a:
"Can I use the CRUD API to look up node A by its ID, create node B from a POCO, create a relationship between A and B"
Cypher 不仅是 future 的方式,也是“现在”的方式。
从 Cypher 开始(有很多相关资源):
START user=node:user(Id: 1234)
CREATE user-[:INVITED]->(user2 { Id: 4567, Name: "Jim" })
Return user2
然后将其转换为 C#:
graphClient.Cypher
.Start(new { user = Node.ByIndexLookup("User", "Id", userId) })
.Create("user-[:INVITED]->(user2 {newUser})")
.WithParam("newUser", new User { Id = 4567, Name = "Jim" })
.Return(user2 => user2.Node<User>())
.Results;
这里还有很多类似的例子:https://github.com/Readify/Neo4jClient/wiki/cypher-examples
问题 1b:
" and add B's ID to a legacy index in one request?"
不,Cypher 不支持遗留索引。如果你真的想继续使用它们,那么你应该坚持使用 CRUD API。没关系:如果您想使用遗留索引,请使用遗留 API。
Q2.
"If not, what is the alternative? Is the CRUD API considered legacy code and should we move towards a Cypher-based Neo4j 2.0 approach?"
这正是您想要做的。 Cypher,带有标签和自动索引:
// One time op to create the index
// Yes, this syntax is a bit clunky in C# for now
graphClient.Cypher
.Create("INDEX ON :User(Id)")
.ExecuteWithoutResults();
// Find an existing user, create a new one, relate them,
// and index them, all in a single HTTP call
graphClient.Cypher
.Match("(user:User)")
.Where((User user) => user.Id == userId)
.Create("user-[:INVITED]->(user2 {newUser})")
.WithParam("newUser", new User { Id = 4567, Name = "Jim" })
.ExecuteWithoutResults();
这里有更多例子:https://github.com/Readify/Neo4jClient/wiki/cypher-examples
Q3.
"Does this Cypher-based approach mean that we lose POCO-to-node translation for create operations? That was very convenient."
正确。但这是我们所有人都想做的事情,Neo4j 的发展方向,以及 Neo4jClient 的发展方向。
想一想 SQL(我假设您很熟悉)。您是否运行查询来查找节点的内部标识符,包括其在磁盘上的文件偏移量,然后在第二个查询中使用此内部标识符来操作它?不需要。您只需运行一次查询即可完成所有操作。
现在,人们喜欢传递 Node<T>
或 NodeReference
实例的一个常见用例是减少查询中的重复。这是一个合理的担忧,但是因为 .NET 中的流畅查询是不可变的,我们可以构建一个基本查询:
public ICypherFluentQuery FindUserById(long userId)
{
return graphClient.Cypher
.Match("(user:User)")
.Where((User user) => user.Id == userId);
// Nothing has been executed here: we've just built a query object
}
然后像这样使用它:
public void DeleteUser(long userId)
{
FindUserById(userId)
.Delete("user")
.ExecuteWithoutResults();
}
或者,添加更多的 Cypher 逻辑来删除所有关系:
然后像这样使用它:
public void DeleteUser(long userId)
{
FindUserById(userId)
.Match("user-[:?rel]-()")
.Delete("rel, user")
.ExecuteWithoutResults();
}
通过这种方式,您可以有效地重用引用,而无需首先通过网络将它们拉回。
关于Neo4jClient:对CRUD API的疑惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19494846/
我有以下变量: string str1 = "1"; string str2 = "asd"; string str3 = "3.5"; string str4 = "a"; 现在我需要找到每个字符串
这个问题在这里已经有了答案: Is Java "pass-by-reference" or "pass-by-value"? (92 个回答) 关闭 8 年前。 public class progr
我对这种行为有些疑惑。谁能解释一下 void Decrement(int* x){ *x--; //using this line, the output is 5
您好 StackOverflow 用户(或 Stackoverflowers?): 我正在通过编写 WPF 代码来学习。我阅读了几篇文章/看到了几个截屏视频,并且来自 WEB 开发背景,我启动了 VS
在阅读 HTML5 IndexedDB Specification 时我对它的异步请求模型有些怀疑。查看 request api example 时, open 方法用于启动异步请求。 var req
有几个问题,首先是这个方法,它将 int[] 转换为 byte[]: public static byte[] intToByte(int[] input){ ByteBuffer byteB
我是一名优秀的程序员,十分优秀!