How to avoid duplicate nodes

The code written below should check if a match is present, if so it should update the value.
Otherwise it should create a node with the given value.

Currently every time I update a organization.Role value it creates an entirely new node.
Even when the organization.Role value is not changed.
So technically 60 seller nodes could be added.
There should only be one role node per organization and its value should just be changed.
I've not been able to figure out why the current behavior happens as stated above.

query = query.Merge("(role:Role {roletype: $newRoleValue})")
                        .OnCreate()
                        .Set("role = $newRole")
                        .WithParam("newRole", new { Name = newTenderVersion.Organization.Role.ToString() })
                        .WithParam("newRoleValue", newTenderVersion.Organization.Role.ToString())
                        .Merge($"(organization)-[:HAS_ROLE]->(role)");

What kind of DSL is that?
What does the generated query look like?

Were does organization come from?
You need to match or merge it first, otherwise it will be created by MERGE.

I'm having trouble reading this as I'm used to Cypher. I'm confused to what you want to do exactly.

When you say

it creates an entirely new node
Do you mean a new Organization node?

But, I believe what you need to do, is have MATCH statements to get the existing Organization nodes you don't want to duplicate.

Then do a MERGE on the the relationships and/or the role Nodes that are new.

Maybe something like:

MATCH (org:Organization) WHERE ...
MERGE(newRole:Role) WHERE ...
MERGE (org)-[:HAS_ROLE]->(newRole)
...

I hope that helps.

Is there not something like a procedure that does this (automatically) for you?