1

当我尝试从 Neo4JClient 中的 cyper 查询中获取结果时,出现以下错误。

错误:

Neo4jClient encountered an exception while deserializing the response from the server. This is likely a bug in Neo4jClient.    
Please open an issue at https://bitbucket.org/Readify/neo4jclient/issues/new    
To get a reply, and track your issue, ensure you are logged in on BitBucket before submitting.    
Include the full text of this exception, including this message, the stack trace, and all of the inner exception details.    

Include the full type definition of <>f__AnonymousType3`2[[Neo4jClient.Node`1[[IQS_ACL.Nodes.User, IQS ACL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], Neo4jClient, Version=1.0.0.594, Culture=neutral, PublicKeyToken=null],[Neo4jClient.Node`1[[IQS_ACL.Nodes.SecurityRelationshipObject, IQS ACL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], Neo4jClient, Version=1.0.0.594, Culture=neutral, PublicKeyToken=null]].

Include this raw JSON, with any sensitive values replaced with non-sensitive equivalents:    

{    
  "columns" : [ "Node", "Rels" ],    
  "data" : [ [ {    
    "paged_traverse" : "http://localhost:7474/db/data/node/7690/paged/traverse/{returnType}{?pageSize,leaseTime}",    
    "outgoing_relationships" : "http://localhost:7474/db/data/node/7690/relationships/out",    
    "data" : {    
      "Name" : "root"    
    },    
    "traverse" : "http://localhost:7474/db/data/node/7690/traverse/{returnType}",    
    "all_typed_relationships" : "http://localhost:7474/db/data/node/7690/relationships/all/{-list|&|types}",    
    "all_relationships" : "http://localhost:7474/db/data/node/7690/relationships/all",    
    "property" : "http://localhost:7474/db/data/node/7690/properties/{key}",    
    "self" : "http://localhost:7474/db/data/node/7690",    
    "properties" : "http://localhost:7474/db/data/node/7690/properties",    
    "outgoing_typed_relationships" : "http://localhost:7474/db/data/node/7690/relationships/out/{-list|&|types}",    
    "incoming_relationships" : "http://localhost:7474/db/data/node/7690/relationships/in",    
    "incoming_typed_relationships" : "http://localhost:7474/db/data/node/7690/relationships/in/{-list|&|types}",    
    "extensions" : {    
    },    
    "create_relationship" : "http://localhost:7474/db/data/node/7690/relationships"    
  }, {    
    "start" : "http://localhost:7474/db/data/node/7690",    
    "data" : {    
      "W" : 3,    
      "R" : 3,    
      "ReadablePermissions" : "+R+W",    
      "X" : 1    
    },    
    "property" : "http://localhost:7474/db/data/relationship/9351/properties/{key}",    
    "self" : "http://localhost:7474/db/data/relationship/9351",    
    "properties" : "http://localhost:7474/db/data/relationship/9351/properties",    
    "type" : "SECURITY",    
    "extensions" : {    
    },    
    "end" : "http://localhost:7474/db/data/node/7696"    
  } ], [ {    
    "paged_traverse" : "http://localhost:7474/db/data/node/7690/paged/traverse/{returnType}{?pageSize,leaseTime}",    
    "outgoing_relationships" : "http://localhost:7474/db/data/node/7690/relationships/out",    
    "data" : {    
      "Name" : "root"    
    },    
    "traverse" : "http://localhost:7474/db/data/node/7690/traverse/{returnType}",    
    "all_typed_relationships" : "http://localhost:7474/db/data/node/7690/relationships/all/{-list|&|types}",    
    "all_relationships" : "http://localhost:7474/db/data/node/7690/relationships/all",    
    "property" : "http://localhost:7474/db/data/node/7690/properties/{key}",    
    "self" : "http://localhost:7474/db/data/node/7690",    
    "properties" : "http://localhost:7474/db/data/node/7690/properties",    
    "outgoing_typed_relationships" : "http://localhost:7474/db/data/node/7690/relationships/out/{-list|&|types}",    
    "incoming_relationships" : "http://localhost:7474/db/data/node/7690/relationships/in",    
    "incoming_typed_relationships" : "http://localhost:7474/db/data/node/7690/relationships/in/{-list|&|types}",    
    "extensions" : {    
    },    
    "create_relationship" : "http://localhost:7474/db/data/node/7690/relationships"    
  }, {    
    "start" : "http://localhost:7474/db/data/node/7690",
    "data" : {
      "W" : 3,
      "R" : 3,
      "ReadablePermissions" : "+R+W",
      "X" : 1
    },
    "property" : "http://localhost:7474/db/data/relationship/9351/properties/{key}",
    "self" : "http://localhost:7474/db/data/relationship/9351",
    "properties" : "http://localhost:7474/db/data/relationship/9351/properties",
    "type" : "SECURITY",
    "extensions" : {
    },
    "end" : "http://localhost:7474/db/data/node/7696"
  } ] ]}

代码:

var groups = clientConnection.Cypher
                .Start(new { n = "node(" + folderID + ")" })
                .Match("n<-[r:SECURITY]-x, x<-[v:IS_MEMBER_OF_GROUP*]-b where b.Name = '"+userName+"'")
                .ReturnDistinct((x, r) => new
                {
                    Node = x.As<Node<User>>(),
                    Rels = r.As<Node<SecurityRelationshipObject>>()
                });

var results = groups.Results;
It throws on the .Results();

如果我运行查询:

START n=node(7706) MATCH n<-[r:SECURITY]-x, x<-[v:IS_MEMBER_OF_GROUP*]-b where b.Name = 'user1' RETURN distinct x AS Node, r AS Rels;

在控制台中它返回:

Node[7700]{Name:"root"} | :SECURITY[9369] {ReadablePermissions:"+R+W",R:3,W:3,X:1} |

Bitbucket 票证:https ://bitbucket.org/Readify/neo4jclient/issue/153/cypher-query-returns-create-bug-exception

类定义:

public class User
{
    //CMIS Object Properties
    public string ObjectId { get; set; }
    public string BaseTypeId { get; set; }
    public string ObjectTypeId { get; set; }
    public IList<string> SecondaryObjectTypeIds { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }
    public string CreatedBy { get; set; }
    public string CreationDate { get; set; }
    public string LastModifiedBy { get; set; }
    public string LastModificationDate { get; set; }
    public string ChangeToken { get; set; }
}

public class UserGroup
{
    //CMIS Object Properties
    public string ObjectId { get; set; }
    public string BaseTypeId { get; set; }
    public string ObjectTypeId { get; set; }
    public IList<string> SecondaryObjectTypeIds { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }
    public string CreatedBy { get; set; }
    public string CreationDate { get; set; }
    public string LastModifiedBy { get; set; }
    public string LastModificationDate { get; set; }
    public string ChangeToken { get; set; }
}

public class RelationshipObject
{
    //CMIS Object Properties
    public string ObjectId { get; set; }
    public string BaseTypeId { get; set; }
    public string ObjectTypeId { get; set; }
    public Array SecondaryObjectTypeIds { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }
    public string CreatedBy { get; set; }
    public string CreationDate { get; set; }
    public string LastModifiedBy { get; set; }
    public string LastModificationDate { get; set; }
    public string ChangeToken { get; set; }

    //RelationshipObject Properties
    public string sourceId { get; set; }
    public string targetId { get; set; }
}

public class SecurityRelationshipObject : RelationshipObject
{
    //CMIS Object Properties
    public IList<string> SecondaryObjectTypeIds { get; set; }
    public string ReadablePermissions { get; set; }
    public int R { get; set; }
    public int W { get; set; }
    public int X { get; set; }
}

关系定义:

public class RelationshipUserGroupToFolder: Relationship<SecurityRelationshipObject>, IRelationshipAllowingSourceNode<UserGroup>, IRelationshipAllowingTargetNode<FolderObject>
{
    string RelationshipName;

    public RelationshipUserGroupToFolder(string RelationshipName, NodeReference targetNode, SecurityRelationshipObject relationshipTypeObject)
        : base(targetNode, relationshipTypeObject)
    {
        this.RelationshipName = RelationshipName;
    }

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

public class RelationshipUserGroupToUserGroup : Relationship<RelationshipObject>, IRelationshipAllowingSourceNode<UserGroup>, IRelationshipAllowingTargetNode<UserGroup>
{
    string RelationshipName;

    public RelationshipUserGroupToUserGroup(string RelationshipName, NodeReference targetNode, RelationshipObject relationshipTypeObject)
        : base(targetNode, relationshipTypeObject)
    {
        this.RelationshipName = RelationshipName;
    }

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

有一些不同的类型,例如RelationshipUserToFolder(security) 或RelationshipUserToUseGroup(IS_MEMBER_OF_GROUP)

4

1 回答 1

1

我很确定问题是由于Rels = ...代码的一部分,因为我很确定您正在尝试将 aRelationship转换为 aNode而 Neo4j 不知道如何做到这一点。此外,JSON.NET(以及通过关联,neo4jclient)不知道如何反序列化,SecurityRelationshipObject因为它(以及它的基类)具有定义的类型Array和属性IList,只有IEnumerable<>集合可以反序列化。

为此,.ReturnDistinct应如下所示:

/* Rest of query here */
.ReturnDistinct((x, r) => new
{
    Node = x.As<Node<User>>(),
    Rels = r.As<RelationshipInstance<SecurityRelationshipObject>>()
});

并且数据对象应如下所示:

public class RelationshipObject {
    /* Other Properties */
    public IEnumerable<string> SecondaryObjectTypeIds { get; set }
}

public class SecurityRelationshipObject : RelationshipObject {
    /* Other Properties */
    public new IEnumerable<string> SecondaryObjectTypeIds { get;set; }
}

虽然很明显,您不需要“安全”版本中的属性,因为它已经在基类中,如果您确实拥有它,您应该使用new关键字来指示它正在替换基类版本。

如果您在这些属性中没有任何内容,它将很好地反序列化,这可能解释了为什么Node = x.As<Node<User>>()工作正常,即使您也有一个IList<>那里。

下面是一个小程序,运行时 ( Tester.Run()) 应该输出 ( Chris has known jeff since yesterday) - 你可以在控制台应用程序中试试这个,看看它是否适合你?您应该能够完整地复制/粘贴它..


using System;
using Neo4jClient;

public static class Tester
{
    public static void Run()
    {
        var client = new GraphClient(new Uri("http://localhost.:7474/db/data"));
        client.Connect();
        NodeReference<User> rootRef = AddData(client);

        var query = client.Cypher.Start(new {n = rootRef})
            .Match("n-[r:KNOWS]->other")
            .Return((other, r) => new
            {
                Other = other.As<Node<User>>(),
                Knows = r.As<RelationshipInstance<KnowsData>>()
            });

        var results = query.Results;

        foreach (var result in results)
            Console.WriteLine("Chris has known {0} since {1}", result.Other.Data.Name, result.Knows.Data.Since);
    }

    private static NodeReference<User> AddData(IGraphClient client)
    {
        var chris = new User {Name = "Chris"};
        var jeff = new User {Name = "Jeff"};

        NodeReference<User> chrisRef = client.Create(chris);
        NodeReference<User> jeffRef = client.Create(jeff);

        client.CreateRelationship(chrisRef, new Knows(jeffRef, new KnowsData {Since = "Yesterday"}));
        return chrisRef;
    }
}

public class User { public string Name { get; set; } }
public class KnowsData { public string Since { get; set; } }

public class Knows : Relationship<KnowsData>, IRelationshipAllowingSourceNode<User>, IRelationshipAllowingTargetNode<User>
{
    public Knows(NodeReference targetNode, KnowsData data) : base(targetNode, data) {}
    public override string RelationshipTypeKey { get { return "KNOWS"; } }
}
于 2013-10-08T13:54:44.467 回答