[英]Create a neo4j database using C#
I'm trying to create a neo4j db using neo4jclient in C#... I want to create a constraint on a label property(ID), return the max value and then create the database. 我正在尝试在C#中使用neo4jclient创建neo4j数据库。我想在标签属性(ID)上创建约束,返回最大值,然后创建数据库。
var neotest = new GraphClient(new Uri("http://localhost:7474/db/data"), "username", "password");
neotest.Connect();
neotest.Cypher
.CreateUniqueConstraint("n:Solution", "n.ID")
.ExecuteWithoutResults();
string queryString = QueryHelper.GetQueryObject(Model);
var neotest1 = new GraphClient(new Uri("http://localhost:7474/db/data"),"username","password");
neotest.Connect();
neotest.Cypher
.Create("(n:Solution{" + queryString + "})")
.ExecuteWithoutResults();
The above code creates a neo4j database and adds constraint to the ID property as well. 上面的代码创建了neo4j数据库,并且还为ID属性添加了约束。
However how do I get the max value of the ID property and increment it accordingly? 但是,如何获取ID属性的最大值并相应地增加它呢?
The cypher query is: 密码查询为:
match(n:Solution)return max(n.ID)
But can't figure out how to implement it and use the max value. 但是无法弄清楚如何实现它并使用最大值。 Please help.
请帮忙。
The query to get the MAX
is: 获取
MAX
的查询为:
var query = client.Cypher
.Match("(n:Solution)")
.Return(() => Return.As<int>("MAX(n.ID)");
Just as a side note - you don't need to Connect
to new instances of the client for each query, you can just do it all via one client instance. 就像一个旁注-您无需为每个查询都
Connect
到客户端的新实例,您只需通过一个客户端实例即可完成所有操作。
In fact - looking at the code, you don't actually even use neotest1
as a variable at all. 实际上-看代码,您甚至根本没有使用
neotest1
作为变量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.