在 Neoj4Client 中检索关系给出反序列化异常

问题描述

我正在尝试从我的数据库中检索与属性的关系。我正在使用 Neo4jClient 和 .NET 。 这是我迄今为止尝试过的:

var client = new GraphClient(new Uri("http://localhost:11007"),"neo4j","jobsjobs");
var JsonContractResolver = new CamelCasePropertyNamesContractResolver();
client.ConnectAsync().Wait();
var createquery = client.Cypher
                        .Match("matched=(a:Technology{name:{to},title:{level}})<-[rel:HOP]-(b:Technology{name:{from},title:{level}})")
                        .WithParam("to","arangoDB")
                        .WithParam("level","Junior")
                        .WithParam("from","Big Table")
                        .Return(rel => rel.As<RelationshipInstance<Hop>>()).ResultsAsync;

foreach (var item in createquery.Result)
{
    Console.WriteLine(item.Data.Cost);
}

这是我的“Hop”关系课:

 public class Hop : Relationship,IRelationshipAllowingSourceNode<Technology>,IRelationshipAllowingTargetNode<Technology>
 {

    [JsonProperty("cost")]
    public long? Cost { get; set; }
    public Hop() : base(-1,null) { }
    public Hop(NodeReference targetNode) : base(targetNode)
    {
    }

    public const string TypeKey = "HOP";

    public override string RelationshipTypeKey
    {
        get { return TypeKey; }
    }

这是我在过去 6 小时内遇到的错误

"发生了一个或多个错误。(Neo4j 返回了一个有效的响应,但是 Neo4jClient 无法反序列化为您提供的对象结构。\r\n\r\n首先,请尝试查看下面的异常以找出问题所在.\r\n\r\n如果不明显,您可以在 http://stackoverflow.com/questions/tagged/neo4jclient\r\n\r\nInclude 处寻求帮助以获取此异常的全文,包括此消息、堆栈跟踪和所有内部异常详细信息。\r\ n\r\n在 Neo4jClient.GraphClient.Neo4jClient.IRawGraphClient.ExecuteGetCypherResultsAsync[TResult](CypherQuery query) 处包含 f__AnonymousType11[[System.String,System.Private.CoreLib,Version=4.0.0.0,Culture=neutral,PublicKeyToken=7cec85d7bea7798e]].\r\n\r\nInclude this raw JSON,with any sensitive values replaced with non-sensitive equivalents:\r\n\r\n (Parameter 'content')) " at Neo4jClient.Serialization.CypherjsonDeserializer1.Deserialize(String content,Boolean isHttp)\r\n 的完整类型定义"

编辑:添加 HOP 关系的 JSON 格式:

{ “身份”:1515, “开始”:1495, “结束”:1491, "type": "HOP",“特性”: { “成本”:3 } }

这是节点的 JSON 格式:

{ “身份”:1491, “标签”: [ “技术” ],“特性”: { "name": "arangoDB","title": "初级" } }

This is the results in graph format

解决方法

通过关系,要获取属性,您只需要提供一个标准的 POCO,因此您应该去:

Hop

将您的查询更改为:

public class Hop
{
    [JsonProperty("cost")]
    public long? Cost {get;set;}
}