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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:42:10+00:00 2026-05-23T23:42:10+00:00

Consider the following class (simplified in order to focus in the core problem): public

  • 0

Consider the following class (simplified in order to focus in the core problem):

public class Question
{
    public virtual string QuestionId { get; set; }

    public virtual string Text { get; set; }

    public virtual string Hint { get; set; }
}

and tables:

Question
- QuestionId ((primary key, identity column and key)
- Code

QuestionTranslation
- QuestionTranslationId (primary key, identity column; not really relevant to the association)
- QuestionId (composite key element 1)
- CultureName (composite key element 2) (sample value: en-US, en-CA, es-ES)
- Text
- Hint

How I can map the Question class so the Text and Hint properties are populated using the current thread’s culture. If the thread’s culture is changed I would like the Text and Hint properties to automatically return the appropriate value without the need for the Question entity to be reloaded.

Note that I’m only outlining the relevant class and properties from the business side. I’m totally open to any new class or property needed to achieve the desired functionality.

  • 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-23T23:42:11+00:00Added an answer on May 23, 2026 at 11:42 pm

    Edited to reflect changed answer:

    public class Question
    {
        public virtual string QuestionId { get; set; }
    
        public virtual string Text
        {
            get
            {
                var currentculture = CultureInfo.CurrentCulture.Name;
                return Translations
                    .Where(trans => trans.CultureName == currentculture)
                    .Select(trans => trans.Text)
                    .FirstOrDefault();
            }
            set
            {
                var currentculture = CultureInfo.CurrentCulture.Name;
                var translation = Translations
                    .Where(trans => trans.CultureName == currentculture)
                    .FirstOrDefault();
                if (translation == null)
                {
                    translation = new QuestionTranslation();
                    Translations.Add(translation);
                }
                translation.Text = value;
            }
        }
        public virtual string Hint
        {
            get
            {
                var currentculture = CultureInfo.CurrentCulture.Name;
                return Translations
                    .Where(trans => trans.CultureName == currentculture)
                    .Select(trans => trans.Hint)
                    .FirstOrDefault();
            }
            set
            {
                var currentculture = CultureInfo.CurrentCulture.Name;
                var translation = Translations
                    .Where(trans => trans.CultureName == currentculture)
                    .FirstOrDefault();
                if (translation == null)
                {
                    translation = new QuestionTranslation();
                    Translations.Add(translation);
                }
                translation.Hint = value;
            }
        }
    
        protected virtual ICollection<QuestionTranslation> Translations { get; set; }
    }
    
    class QuestionTranslation
    {
        public virtual int Id { get; protected set; }
        public virtual string CultureName { get; set; }
        public virtual string Text { get; set; }
        public virtual string Hint { get; set; }
    }
    
    <class name="Question" xmlns="urn:nhibernate-mapping-2.2">
      <id name="QuestionId" column="QuestionId"/>
    
      <bag name="Translations" table="QuestionTranslation" lazy="true">
        <key>
          <column name="QuestionId"/>
        </key>
        <one-to-many class="QuestionTranslation"/>
      </bag>
    </class>
    
    <class name="QuestionTranslation" table="QuestionTranslation" xmlns="urn:nhibernate-mapping-2.2">
      <id name="QuestionTranslationId"/>
      <many-to-one name="ParentQuestion" column="QuestionId"/>
    </class>
    

    if you have a lot of translations then change ICollection<QuestionTranslation> Translations { get; set; } to IDictionary<string, QuestionTranslation> Translations { get; set; } and map as <map> but normally the above should do it

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

Sidebar

Related Questions

consider the following class: public class ShortName { public string ValueString { get; set;
Consider the following: class Bind { public string x { get; set; } public
Consider the following simplified objects and relationships: public class Job{ int JobId; String name;
Consider the following class hierarchy: public class Foo { public string Name { get;
Consider the following class public class Class1 { public int A { get; set;
consider the following class: class Order { int OrderId {get; set;} int CustomerId {get;
consider the following class and struct public class Entity { public IdType Id {get;set;}
Consider the following class: public class ComponentA { public ComponentB ComponentB { get; set;
Consider the following set of classes/Interfaces: class IFish{ public: virtual void eat() = 0;
Consider following example : public class SomeBusinessLayerService : DataService<MyEntityContainer> { [WebInvoke] void DoSomething(string someParam)

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.