建立关系

时间:2017-04-20 13:07:30

标签: neo4jclient

我已经和我争斗了两天而且不知所措。我正在尝试创建节点关系并严重失败。

这是我创建和运行关系的代码。

model {
  for (i in 1:I)
  {
      Z[i] ~ dnorm(mu[i], tau)
      mu[i]<- beta0 + beta1 * X[i]
  }
  tau <- 1/(sigma*sigma)
  sigma ~ dunif(0, 100)
  beta0 ~ dnorm(0, 1.0E-6)
  beta1 ~ dnorm(0, 1.0E-6)
 }

这是AttackPatterns类。

var query = graphClient.Cypher
  .Match("(apt_1:AttackPatterns)", "(apt_2:AttackPatterns)")
  .Where((AttackPatterns apt_1) => apt_1.Id == Convert.ToInt64(apt.ID))
  .AndWhere((AttackPatterns apt_2) => apt_2.Id == Convert.ToInt64(rt.Relationship_Target_ID))
  .CreateUnique("(apt_1)-[:" + rtrn.ToString() + "]->(apt_2)");

query.ExecuteWithoutResults();

在运行时期间,查询的值在一次迭代中等同于:

MATCH(apt_1:AttackPatterns),(apt_2:AttackPatterns)\ r \ nWHERE(apt_1.Id = \“1 \”)\ r \ nAND(apt_2.Id = \“122 \”)\ r \ n \ nCREATE UNIQUE (apt_1) - [:ChildOf] - GT;(apt_2)

我注意到“\ r \ n”字符。我还注意到1和122左右的引号。当我将其粘贴到Neo4j Web界面中,将“\ r \ n”替换为实际的新行并删除引号前的“\”转义字符时,它会失败。如果我删除1和122周围的引号,它会成功创建关系。

我真的不确定我做错了什么,并希望得到任何帮助!

1 个答案:

答案 0 :(得分:0)

I've made some assumptions about types, as I think I know what's going on - basically - the Convert.ToInt64 isn't called before the query is made, you have to do it outside of the query generation:

//Given:
var apt = new { ID = "1" };

//Convert outside query
var ap1Id = Convert.ToInt64(apt.ID);

//Use in query
var query = gc.Cypher
    .Match("(apt_1:AttackPatterns)", "(apt_2:AttackPatterns)")
    .Where((AttackPatterns apt_1) => apt_1.Id == ap1Id) // <-- using locally created var
/* etc */

The \r\n is just for formatting when you look at the DebugQueryText property, they're not sent across, the only problem is the " around the numbers.

Please feel free to add this as a bug to the github project and I'll have a look into it, ideally it would be executed beforehand, but it's possibly like this for a reason.