尝试查看如下查询中的关系:
var query = _graph.Cypher.Start(
new
{
me = Node.ByIndexLookup("node_auto_index", "id", p.id)
}).Match("me-[r:FRIENDS_WITH]-friend")
.Where((Person friend) => friend.id == f.id)
.Return<FriendsWith>("r");下面是FriendsWith类。我不能为FriendsWith添加无参数构造函数,因为基类(关系)没有无参数构造函数。
public class FriendsWith : Relationship,
IRelationshipAllowingSourceNode<Person>,
IRelationshipAllowingTargetNode<Person>
{
public FriendsWith(NodeReference<Person> targetNode)
: base(targetNode)
{
__created = DateTime.Now.ToString("o");
}
public const string TypeKey = "FRIENDS_WITH";
public string __created { get; set; }
public override string RelationshipTypeKey
{
get { return TypeKey; }
}
}但是我得到了错误“没有为这个对象定义无参数的构造函数”。当我尝试运行它的时候。为查询返回关系的正确方式是什么?
堆栈跟踪
at Neo4jClient.Deserializer.CypherJsonDeserializer1.Deserialize(String content) in c:\TeamCity\buildAgent\work\f1c4cf3efbf1b05e\Neo4jClient\Deserializer\CypherJsonDeserializer.cs:line 53 at Neo4jClient.GraphClient.<>c__DisplayClass1d1.b__1c(Task1 responseTask) in c:\TeamCity\buildAgent\work\f1c4cf3efbf1b05e\Neo4jClient\GraphClient.cs:line 793 at System.Threading.Tasks.ContinuationResultTaskFromResultTask2.InnerInvoke() at System.Threading.Tasks.Task.Execute()
发布于 2013-10-26 07:04:33
只需将其反序列化为表示数据结构的POCO:
public class FriendsWith
{
public string __created { get; set; }
}
var query = _graph.Cypher
.Start(new {
me = Node.ByIndexLookup("node_auto_index", "id", p.id)
})
.Match("me-[r:FRIENDS_WITH]-friend")
.Where((Person friend) => friend.id == f.id)
.Return(r => r.As<FriendsWith>())
.Results;您实际上根本不需要FriendsWith : Relationship, IRelationshipAllowingSourceNode<Person>, IRelationshipAllowingTargetNode<Person>类。
使用Cypher创建关系:
_graph.Cypher
.Start(new {
me = Node.ByIndexLookup("node_auto_index", "id", p.id),
friend = Node.ByIndexLookup("node_auto_index", "id", p.id + 1)
})
.CreateUnique("me-[:FRIENDS_WITH {data}]->friend")
.WithParams(new { data = new FriendsWith { __created = DateTime.Now.ToString("o") } })
.ExecuteWithoutResults();您将在Neo4jClient维基上看到更多示例。基本上,在这个时代,一切都应该是Cypher。
https://stackoverflow.com/questions/16433030
复制相似问题