简体   繁体   English

neo4j c#中的通用关系

[英]generic ralationship in neo4j c#

I need to establish a relationship between two different node type like this: 我需要在两个不同的节点类型之间建立关系,如下所示:

   public class Fallow<T,U>: Relationship,
            IRelationshipAllowingSourceNode<T>,
    IRelationshipAllowingTargetNode<U>
{
    public Fallow(NodeReference targetNode)
        : base(targetNode)
    {


    }
    public const string TypeKey = "FALLOW";
    public DateTime relationDate { get; set; }
    public override string RelationshipTypeKey
    {
        get { return TypeKey; }
    }
}

I have an error: 我有一个错误:

Error   1   'Biber10.Neo4j.Fallow<T,U>' cannot implement both 'Neo4jClient.IRelationshipAllowingParticipantNode<T>' and 'Neo4jClient.IRelationshipAllowingParticipantNode<U>' because they may unify for some type parameter substitutions  C:\Users\turgut\Documents\Visual Studio 2013\Projects\Biber10\Biber10.Neo4j\Fallow.cs   10  18  Biber10.Neo4j

How do I fix it?. 我如何解决它?。

Thanks. 谢谢。

We've moved away from the use of Relationship like this, the best example of the thing you're trying to do would be something like this: 我们已经不再使用像这样的Relationship ,您想要做的事情的最好例子就是这样:

public class Fallow
{
    public const string TypeKey = "FALLOW";
    public DateTime RelationDate { get; set; }
}

Used like so: 像这样使用:

//Just using this to create a demo node
public class GeneralNode
{
    public string AValue { get; set; }
}

var gc = new GraphClient(new Uri("http://localhost.:7474/db/data/"));
gc.Connect();

//Create
var node1 = new GeneralNode { AValue = "val1"};
var node2 = new GeneralNode { AValue = "val2" };
var fallow = new Fallow { RelationDate = new DateTime(2016, 1, 1)};

gc.Cypher
    .Create($"(n:Value {{node1Param}})-[:{Fallow.TypeKey} {{fallowParam}}]->(n1:Value {{node2Param}})")
    .WithParams(new
    {   
        node1Param = node1,
        node2Param = node2,
        fallowParam = fallow
    })
    .ExecuteWithoutResults();

//Get
var query = gc.Cypher
    .Match($"(n:Value)-[r:{Fallow.TypeKey}]->(n1:Value)")
    .Return(r => r.As<Fallow>());

var results = query.Results;
foreach (var result in results)
{
    Console.WriteLine("Fallow: " + result.RelationDate);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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