I have a situation where I need to store a graph data structure in the database.
This means an entity can have unlimited number of related entities of the same type (related entity can have unlimited related entities as well).
I was thinking that many-to-many relationship would solve my problem.
I’m trying to do mapping with FluentNHibernate, but following code does not generate SQL for CREATE TABLE for EntityEntity table:
HasManyToMany(x => x.RelatedEntities).ChildKeyColumn("RelateEntityID").ParentKeyColumn("EntityID");
Am I doing something wrong? Or should I create a separate entity and do mapping using HasMany()?
Thank You very much!
Regarding to your question I will create an entity which has one parent and a list of children.
here is my sample:
and the mapping override class is:
as you can see one node could have a parent and a list of children.
and here is my table structure, please ignore DeletedBy and DeletedDate (ower AdvanceEntity is a soft deletable entity)
If you need some unittests to see how it work let me know.