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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:40:06+00:00 2026-05-23T17:40:06+00:00

I have the following data structure : +———+ |Resume | +———+ |Id (PK) |

  • 0

I have the following data structure :

+---------+
|Resume   |
+---------+
|Id (PK)  |
|IsActive |
|...      |
|..       |
|.        |
+---------+

+--------------------+
|Resume_Translation  |
+--------------------+
|ResumeId (PK, FK)   |
|Language (PK)       |
|Title               |
|Description         |
|...                 |
|..                  |
|.                   |
+--------------------+

So I could have such a data with two joined tables :

+----------------------------------------------------------+
|Id | IsActive | ResumeId | Language | Title | Description |
+----------------------------------------------------------+
|1  | true     | 1        | 'fr'     | 'One' | 'One desc'  |
|1  | true     | 1        | 'pl'     | 'Raz' | 'Raz Opis'  |
|2  | true     | 2        | 'fr'     | 'B'   | 'bla bla'   |
|3  | true     | 3        | 'fr'     | 'C'   | 'C bla bla' |
+----------------------------------------------------------+

From my domain point of view I care only about Resume entity. I don’t want to have Resume entity with its collection of Resume_Translations because I would only have one Resume entity with a current translation.

public class Resume
{
    public virtual int Id{ get; protected internal set; }

    public virtual string Language { get; protected internal set; }

    public virtual string Title { get; protected internal set; }

    public virtual string Description { get; protected internal set; }

    public virtual bool IsActive { get; protected internal set; }
}

My current mapping with Fluent NHibernate is as follows :

public class ResumeMap : ClassMap<Resume>
{

    public ResumeMap()
    {
        Table("Resume");
        Id(x => x.Id);
        Map(x => x.IsActive);
        // other properties
        Join("Resume_Translation", m =>
                        {
                            m.Fetch.Join();
                            m.Map(x => x.Language).Length(5);
                            m.Map(x => x.Title).Length(100);
                            m.Map(x => x.Description).Length(200);
                        });
    }
}

I can get what I want from the repository without problem just passing in the WHERE predicate the Id of Resume and the Language I want to.

However I have some problems with Inserting and Updating the values.

My question is: How I would define a mapping that NHibernate Inserts a new record only in Resume_Translation table instead of Updating the record for the current entity ?

So what I want to achieve is if I have in the database the following record :

|2  | true     | 2        | 'fr'     | 'B'   | 'bla bla'   |

Join is good for one to one relationship between tables so if I get this into my entity and I change the language and translation, nhibernate is performing an update and I can understand it. If I try to add a new entity with the same Id by different language and translation, nhibernate yields an error that a key already exists and I understand it also.

So, certainly I’m going down the wrong path, but If some one could point me to the correct solution on how I could achieve a mapping that I want I would greatly appreciate.

Another question, how do you deal with a entities and theirs translations from the business point of view ?

Thanks, in advance for your help.

Thomas

  • 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-23T17:40:06+00:00Added an answer on May 23, 2026 at 5:40 pm

    Stefan is on the right track. I’ve tweaked his suggestion to have a bi-directional association which would make updating a lot easier. One catch with this approach is that you need to manually assign the Resume property of the ResumeTranslation instance when inserting so that NHibernate will properly assign the Resume table key to the ResumeTranslation row. So, given the associations you are mapping, this is how it would look in Fluent NH:

    public class ResumeTranslation
    {
        public virtual string Title { get; protected internal set; }
    
        public virtual string Description { get; protected internal set; }
    
                 //Needed for bi-directional association:
        public virtual Resume Resume { get; set; }
    }
    
    
    public class ResumeTranslationMap : ClassMap<ResumeTranslation>
    {
    
        public ResumeTranslationMap()
        {
            Table("ResumeTranslation");
            CompositeId()
                .KeyReference(kp => kp.Resume, "ResumeId")
                .KeyProperty(kp => kp.Language, "Language");
    
            Map(x => x.Title);
            Map(x => x.Description);
        }
    }
    
    public class ResumeMap : ClassMap<Resume>
    {
    
        public ResumeMap()
        {
            Table("Resume");
            Id(x => x.Id);
            Map(x => x.IsActive);
            // other properties
    
            HasMany(c => c.Translations)
                .Inverse()
                .KeyColumn("id") //May not be required but here for reference
                .Cascade.All();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following structure with example data: id season_id title 1 1 Intro 2
I have the following data structure (a list of lists) [ ['4', '21', '1',
I have something like the following data structure: Category StartDateTime EndDateTime =============================================== 1 12/1/2009
I have an odd linq subquery issue. Given the following data structure: Parents Children
I have the following casting problem when my data structure sSpecificData contains a field
If I have a requirement to create a data structure that has the following
I have a table emp with following structure and data: name dept salary -----
I have the following directory structure: +-archive +-a +-data.txt +-b +-data.txt +-incoming +-a +-data.txt
Let's say we have a solution with the following structure: Project.DAL - Data access
I have the following data structure in my database: LastName FirstName CourseName John Day

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.