Neo4jClient - 查询关系
想看看在查询这样的关系:Neo4jClient - 查询关系
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; }
}
}
但我得到错误“没有无参数的构造函数为这个对象定义。”当我尝试运行它。什么是返回查询关系的正确方法?
堆栈跟踪
在Neo4jClient.Deserializer.CypherJsonDeserializer 1.Deserialize(String content) in c:\TeamCity\buildAgent\work\f1c4cf3efbf1b05e\Neo4jClient\Deserializer\CypherJsonDeserializer.cs:line 53 at Neo4jClient.GraphClient.<>c__DisplayClass1d
1.b__1c(任务1 responseTask) in c:\TeamCity\buildAgent\work\f1c4cf3efbf1b05e\Neo4jClient\GraphClient.cs:line 793 at System.Threading.Tasks.ContinuationResultTaskFromResultTask
2.InnerInvoke() 在System.Threading.Tasks.Task.Execute()
只是反序列化到一个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>
类在所有
使用暗号创建关系:
_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。
他试图查看或返回关系。不要创建一个新的。我也有同样的问题。 – Frenchie 2014-03-27 14:27:57
@Frenchie:我的答案的第一部分显示了关系有效载荷的检索。 – 2014-03-27 21:38:34
@Frenchie:如果这不能解决你的具体情况,请提出一个新问题,以便我们讨论它。 – 2014-03-27 21:38:56
满堆栈跟踪? FriendsWith的外观如何? – 2013-05-08 06:55:16
也许你错过了类“FriendsWith”的默认(无参数)构造函数? – veljkoz 2013-05-08 15:05:28
你可以添加一个默认的构造函数,你只需将一个虚拟值传递给基类构造函数,就像这样:public FriendsWith():base(-1){} – 2013-08-27 13:16:17