Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3277764
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:24:21+00:00 2026-05-17T19:24:21+00:00

I have a situation where I need to store a graph data structure in

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T19:24:21+00:00Added an answer on May 17, 2026 at 7:24 pm

    Regarding to your question I will create an entity which has one parent and a list of children.

    here is my sample:

    public class GrafNode : AdvanceEntity
        {
            public GrafNode()
            {
                this.Children = new List<GrafNode>();
            }
    
            public virtual string Name  { get; set; }
    
            public virtual GrafNode Parent { get; set; }
    
            public virtual IList<GrafNode> Children { get; private set; }
    
            public virtual void AddChild(GrafNode node)
            {
                node.Parent = this;
                this.Children.Add(node);
            }
        }
    

    and the mapping override class is:

    public class GrafNodeMappingOverride : IAutoMappingOverride<GrafNode>
    {
        public void Override(AutoMapping<GrafNode> mapping)
        {
            mapping.HasOne(x => x.Parent);
            mapping.HasMany(x => x.Children).KeyColumn("parentId");
        }
    }
    

    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)

    alt text

    If you need some unittests to see how it work let me know.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So this is sort of an exceptional case situation - I have a plugin
The situation is akin to the following: Assume I am a store selling fruits,
Situation: I got news. NEws are posted in multiple categories. Issue: How to store
Here is my situation: User A must monitor the results of an sql query
This is more of a question about best pattern and practice than asking about
Should items like Foreign Keys, Constraints, Default Values, etc be handled by the Database
I would like to know what are the weaknesses of the arrays. I think
I want my JS to load certain information that needs to come from the
Apologies if the question is a little imprecise, but I'll describe my problem below.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.