Neo4j:CreateRelationship中的参数无效
本文关键字:参数 无效 CreateRelationship Neo4j | 更新日期: 2023-09-27 18:27:14
我正在C#中试用Neo4jClient,遇到以下错误:
与"Neo4jClient.IGraphClient.CreateRelationship(Neo4jClient.NodeReference,GraphDB.PrecedesRelationship)"匹配的最佳重载方法包含一些无效参数。
此错误适用于具有以下代码的线路:
client.CreateRelationship<Process,PrecedesRelationship>(prevProcess, new PrecedesRelationship(currProcess, new PrecedesData(product, isOptional)));
这里,prevProcess和currProcess都是Neo4jClient.NodeReference类型。实际上,我生成节点并将它们的NodeReference值存储在字典中,这样我就可以很容易地查找它们。节点创建得很好。
以下是我的课程:
public class Process
{
public string Name { get; set; }
}
,
public class PrecedesData
{
public string Name { get; set; }
public bool IsOptional { get; set; }
public PrecedesData()
{ }
public PrecedesData(string name)
{
this.Name = name;
this.IsOptional = false;
}
public PrecedesData(string name, bool isOptional)
{
this.Name = name;
this.IsOptional = IsOptional;
}
}
和
public class PrecedesRelationship : Relationship<PrecedesData>, IRelationshipAllowingSourceNode<Process>,
IRelationshipAllowingTargetNode<Process>
{
public static readonly string TypeKey = "PRECEDES";
public PrecedesRelationship(NodeReference targetNode, PrecedesData data)
: base(targetNode, data)
{ }
public override string RelationshipTypeKey
{
get { return TypeKey; }
}
}
当我在CreateRelationship中省略类型时,我会得到编译器无法推断类型的错误。
我看了Neo4jClientWiki上的例子,我认为我做对了,但我似乎错了。
我在这里错过了什么?
您应该使用Cypher,因为REST API越来越传统。真的,任何非Cypher的东西都在成为遗产。
client.Cypher
.Start(new { prevProcess, currProcess })
.CreateUnique("prevProcess-[:PRECEDES {precedes}]->currProcess")
.WithParams(new { precedes = new PrecedesData(product, isOptional) })
.ExecuteWithoutResults();
然后,您也不需要任何关系类。
此外,如果您删除多余的构造函数,您可以将整个代码示例缩短为以下内容:
public class PrecedesData
{
public string Name { get; set; }
public bool IsOptional { get; set; }
}
client.Cypher
.Start(new { prevProcess, currProcess })
.CreateUnique("prevProcess-[:PRECEDES {precedes}]->currProcess")
.WithParams(new { precedes = new PrecedesData { Name = product, IsOptional = isOptional } })
.ExecuteWithoutResults();