简体   繁体   中英

Neo4JClient: How can I find a list of relationships (of any type) for a given node?

I know how to get the related nodes, and to specify the relationships to find those nodes, but there doesn't seem to be any mechanism to find the relationships themselves?

Looking through the source code for Neo4JClient you can find the type "Relationship" but it's only used when creating Relationships, not in retrieving them.

When retrieving, you can get a "RelationshipInstance", but it consists of a RelationshipReference and two NodeReferences.. None of which have any data associated with them besides the unique integer ID associated with each.

It sounds like you want access to data stored on relationships. We refer to these as "payloads".

You can query them like so:

client
    .RootNode
    .OutE<FooPayload>()
    .Select(p =>
    {
        p.Reference.Id,         // Relationship ID
        p.StartNodeReference,   // Outbound vertex
        p.EndNodeReference,     // Inbound vertex
        p.Data,                 // Payload as FooPayload
        p.Data.Bar              // A property in the payload
    });

More likely, you'd want to use an overload of OutE that filters the relationships by type, like:

client
    .RootNode
    .OutE<FooPayload>("HAS_FOO")

If you use the overload of OutE without the generic type parameter, you will get the references but no payload data (because we don't know what to deserialize the data into).

HTH.

-- Tatham

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM