I’m trying to create a test application that shows event dependencies: i.e. a resulting dependency graph (as opposed to just a tree graph). Something like:
public class Event() {
public virtual int Id {get;set;}
public virtual IList<Event> Dependencies {get;set;}
}
The other requirement is that I be able to traverse the graph in both directions: given any one event, I can access its dependencies as well as its prerequisites using Nhibernate.
Many events can be dependent on one event occuring… but also any given event may depend on many other events.
What should the model look like (or does this require more than one model)? How can it be mapped using Fluent NHibernate? And is there a configuration/mapping that would protect against circular references?
We do something similar to this and the way its mapped is that the dependent Events should have a column that map up to a parent event. This creates the necessary parent/child relationship that you need for the mapping to be valid and prevent some kind of circular reference. We switched to NH 3.2 by code mappings, so my fluent might be a little shoddy but heres my best guess:
Edit:
Sorry – didn’t see you wanted a HasManyToMany. That might look something like:
This should map away the linking table you will need. You will need to guard against some amount of the “circularness” yourself – that is, make sure in your business logic that you can’t create a loop or some kind of massive object graph dependency issue.