Search code examples
c#neo4jneo4jclient

How to add edges by unwind using neo4jclient?


The nodes have existed. I tried to add edges by unwind,but my function importBuyConnectionIntoNeo4j didn't work,

Is there any one can help me?

the data structure:

class Connection
{
    private string type;

    public string Type
    {
        get { return type; }
        set { type = value; }
    }

    private string source;

    public string Source
    {
        get { return source; }
        set { source = value; }
    }

    private string target;

    public string Target
    {
        get { return target; }
        set { target = value; }
    }       
}

class BuyConnection:Connection
{

}

myFunction:

    public void importBuyConnectionIntoNeo4j(List<BuyConnection> connectionList)
    {
        GraphClient client = createConnectionToNeo4j();
        client.Cypher
            .Unwind(connectionList, "connection")
            .Match("(source:Person),(target:Vegetable)")
            .Where("source.Name=connection.Source AND target.Type=connection.Target")
            .Create("(source)-[:Buy]->(target)")
            .ExecuteWithoutResults();
    }

Solution

  • I think the issue is with your .where text:

    .Where("source.Name=connection.Source AND target.Type=connection.Target")

    is the Source and Target the right way around?