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 3986834
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T06:03:42+00:00 2026-05-20T06:03:42+00:00

I have a thesaurus application built on NHibernate. The data model is very straight-forward:

  • 0

I have a thesaurus application built on NHibernate. The data model is very straight-forward:

public class Word
{
    public virtual int Id { get; set; }
    public virtual string Text { get; set; }
    public virtual IList<Word> Synonyms { get; set; }
    public virtual IList<Word> Antonyms { get; set; }
}

So each word has a list of synonyms and a list of antonyms. I thought the mapping would be straight-forward as well:

public class WordMapping : ClassMap<Word>
{
    public WordMapping()
    {
        Id(x => x.Id);
        Map(x => x.Text);
        HasMany(x => x.Synonyms).Cascade.AllDeleteOrphan();
        HasMany(x => x.Antonyms).Cascade.AllDeleteOrphan();
    }
}

When I look at the table generated in MS SQL Server 2008, I only see one key column for the two HasMany relations:

Id        int
Text      nvarchar(255)
Word_id   int

I think this is causing some weird things to happen when I insert data. When I get the lists after doing some insertions, both Synonyms and Antonyms contain the same Words, but the Words are just seemingly-arbitrary subsets of what should be in the two lists.

Do I have the problem pegged right? If so, how can I fix it?

  • 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-20T06:03:43+00:00Added an answer on May 20, 2026 at 6:03 am

    I was way off base. I assumed FNH was generating a separate table for the HasMany relationships (it wasn’t). Proper code found here: Fluent NHibernate Self Referencing Many To Many

    Specific to my problem, I created two separate tables:

    -- Synonyms table --
    WordId        int
    SynonymId     int
    
    -- Antonyms table --
    WordId        int
    AntonymId     int
    

    Then in my mapping class:

    public class WordMapping : ClassMap<Word>
    {
        public WordMapping()
        {
            Id(x => x.Id);
            Map(x => x.Text);
            HasManyToMany(x => x.Synonyms).ParentKeyColumn("WordId")
                                                  .ChildKeyColumn("SynonymId")
                                                  .Table("Synonyms");
            HasManyToMany(x => x.Antonyms).ParentKeyColumn("WordId")
                                                  .ChildKeyColumn("AntonymId")
                                                  .Table("Antonyms");
        }
    }
    

    That fixes all the issues.

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

Sidebar

Related Questions

I have a Word model for a dictionary/thesaurus: public class Word { public virtual
Have just started using Visual Studio Professional's built-in unit testing features, which as I
Have you used VS.NET Architect Edition's Application and System diagrams to start designing a
Have a n-tire web application and search often times out after 30 secs. How
I have seen this image swirl effect on a visual thesaurus. Is there any
I have 2 tables : The table Data : id , plus many fields.
I have a scenario where a thesaurus has to be created. Instead of storing
Basically, what I'm trying to do is have VIM search for dictionary/thesaurus results using
Have a xml data like <Items><Item><name>test1</name></Item><Item><name>test2</name></Item></Items> Looks like jaxb cannot unmashall this when defining
Have a look at this code: #include <iostream> using namespace std; int main() {

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.