Cypher查询返回Create Bug Exception

时间:2013-10-08 08:59:52

标签: neo4j cypher neo4jclient

当我尝试从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(安全)或RelationshipUserToUseGroup(IS_MEMBER_OF_GROUP)

1 个答案:

答案 0 :(得分:1)

我很确定问题是由Rels = ...位代码造成的,因为我很确定你试图将Relationship转换为Node而Neo4j没有我不知道该怎么做。此外,JSON.NET(以及关联,neo4jclient)不知道如何反序列化SecurityRelationshipObject,因为它(它的基类)具有类型为ArrayIList的属性,只能对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; }
}

虽然很明显,你不需要'Security'版本中的属性,因为它已经在基类中,但是如果你有它,你应该使用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"; } }
}