Which verb
The six verbs differ only in what they do when the relation is already there, or when the cardinality leaves no room:
| Verb | Already related | "One" side already taken | Not related |
|---|---|---|---|
AddRelation |
throws | throws | adds, at the end |
SetRelation |
does nothing | removes what is in the way, then adds | adds |
RemoveRelation |
removes | – | throws |
ClearRelation |
removes | – | does nothing |
ClearRelations(from, expr) |
removes every relation on that side | – | does nothing |
ClearAndSetRelation |
clears the side, then sets exactly the given nodes | – | – |
AddRelation is strict and SetRelation is forgiving. On a One, OneFrom or OneTo side,
SetRelation works like an assignment, because it removes the node that was there:
db.SetRelation<IEvent>(ev, e => e.Venue, otherVenue); // moves the event to another venueAddRelation puts the new node at the end of the list. To change the order, use the
MoveRelation… methods of §9.1 rather than removing and adding
again:
db.MoveRelationToTop<IVenue>(venue, v => v.Events, headliner);