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

  • Home
  • SEARCH
  • 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 3941668
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:34:14+00:00 2026-05-20T00:34:14+00:00

I have a Word model for a dictionary/thesaurus: public class Word { public virtual

  • 0

I have a Word model for a dictionary/thesaurus:

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

Where each Word has many Synonyms and Antonyms. Word has a mapping of:

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

In my controller, I have a simple lookup method for a word:

public ActionResult Word(string word)
{
    using (var session = MvcApplication.SessionFactory.OpenSession())
    {
        using (var transaction = session.BeginTransaction())
        {
            var result = session.QueryOver<Word>()
                                .Where(w => w.Text == word)
                                .SingleOrDefault();

            if(result == null)
                RedirectToAction("InvalidWord");

            ViewBag.Synonyms = result.Synonyms.Select(t => t.Text);
            ViewBag.Antonyms = result.Antonyms.Select(t => t.Text);

            return View(result);
        }
    }
}

When I print out the ViewBag collections in my view, they are both the same. They are some seemingly arbitrary selection of elements from both bags, but not the whole bags.

Update: Below is my code to commit the Words to the database, if that helps. When I print out words after the commit, all the synonyms are correct.

List<Word> words;
...
using (var session = MvcApplication.SessionFactory.OpenSession())
{
    // populate the database
    using (var transaction = session.BeginTransaction())
    {
        foreach (var word in words)
            session.Save(word);

        transaction.Commit();
    }
}

PrintWords(words);
  • 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-20T00:34:15+00:00Added an answer on May 20, 2026 at 12:34 am

    Try using an identity column Id instead of the Text property:

    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; }
    }
    

    and then:

    Id(x => x.Id);
    Map(x => x.Text);
    HasMany(x => x.Synonyms);
    HasMany(x => x.Antonyms);
    

    UPDATE:

    Here’s a full working example (using SQLite and a console application to simplify but similar techniques could be applied in your web application):

    // Domain layer
    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; }
    }
    
    // Mapping layer
    public class WordMapping : ClassMap<Word>
    {
        public WordMapping()
        {
            Id(x => x.Id).UnsavedValue(0);
            Map(x => x.Text);
            HasMany(x => x.Synonyms).Cascade.AllDeleteOrphan();
            HasMany(x => x.Antonyms).Cascade.AllDeleteOrphan();
        }
    }
    
    // Data access layer
    class Program : InMemoryDatabase
    {
        static void Main(string[] args)
        {
            using (var p = new Program())
            {
                // save some dummy data into the database
                var word = new Word
                {
                    Text = "myword",
                    Synonyms = new[]
                    {
                        new Word { Text = "synonym 1" },
                        new Word { Text = "synonym 2" },
                    }.ToList(),
                    Antonyms = new[]
                    {
                        new Word { Text = "antonym 1" },
                    }.ToList()
                };
                using (var tx = p.Session.BeginTransaction())
                {
                    p.Session.Save(word);
                    tx.Commit();
                }
    
                // and now let's query the database
                using (var tx = p.Session.BeginTransaction())
                {
                    var result = p.Session
                                  .QueryOver<Word>()
                                  .Where(w => w.Text == "myword")
                                  .SingleOrDefault();
    
                    var synonyms = result.Synonyms.Select(t => t.Text).ToArray();
                    Console.WriteLine("-- Synonyms --");
                    foreach (var item in synonyms)
                    {
                        Console.WriteLine(item);
                    }
    
                    var antonyms = result.Antonyms.Select(t => t.Text).ToArray();
                    Console.WriteLine("-- Antonyms --");
                    foreach (var item in antonyms)
                    {
                        Console.WriteLine(item);
                    }
                }
            }
        }
    }
    
    public abstract class InMemoryDatabase : IDisposable
    {
        private static Configuration _configuration;
        private static ISessionFactory _sessionFactory;
    
        protected ISession Session { get; set; }
    
        protected InMemoryDatabase()
        {
            _sessionFactory = CreateSessionFactory();
            Session = _sessionFactory.OpenSession();
            BuildSchema(Session);
        }
        private static ISessionFactory CreateSessionFactory()
        {
            return Fluently.Configure()
                .Database(SQLiteConfiguration.Standard.InMemory().ShowSql())
                .Mappings(M => M.FluentMappings.AddFromAssemblyOf<WordMapping>())
                .ExposeConfiguration(Cfg => _configuration = Cfg)
                .BuildSessionFactory();
        }
    
        private static void BuildSchema(ISession Session)
        {
            SchemaExport export = new SchemaExport(_configuration);
            export.Execute(true, true, false, Session.Connection, null);
        }
    
        public void Dispose()
        {
            Session.Dispose();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a set of Word documents which I want to publish using a
I have a Word 2003 .dot template that changes its menu based on the
I have a Word document that starts with a Table of Contents. I need
I have a word : [lesserthen] , that I need to replace with <
I have a Word.Field object which is a checkbox and the Type property equals
I have a simple Word to Pdf converter as an MSBuild Task. The task
I'm making my way into web development and have seen the word postback thrown
I am finishing up a Drupal site and I have attached a word document
Looking for advice (perhaps best practice). We have a MS Word document (Office 2007)
I have a template in word (.docx) format and want to replace some placeholders

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.