Search code examples
c#neo4jneo4jclient

Create Unique Relationship with additional attributes to the relationship


I am creating a Unique Relationship using the following code:

client.Cypher
    .Match("(en1:Entity)", "(en2:Entity)")
    .Where((Entity en1) => en1.EntityName == sParentEntity)
    .AndWhere((Entity en2) => en2.EntityName == sChildEntity)
    .CreateUnique("en1-[:sRelationName]->en2")
    .ExecuteWithoutResults();

For the added relationship, I want to add an attribute named "category" which will take string values.

Is this possible, if so what could be the addition to the above code snippet.


Solution

  • Try replacing the last two lines with this code:

    .CreateUnique("en1-[:sRelationName { category: {category_name} }]->en2")
    .WithParams(new {category_name = "YourCategoryHere"});
    .ExecuteWithoutResults();