I have the following data structure:
+---------+ |Resume | +---------+ |Id (PK) | |IsActive | |... | |.. | |. | +---------+ +--------------------+ |Resume_Translation | +--------------------+ |ResumeId (PK, FK) | |Language (PK) | |Title | |Description | |... | |.. | |. | +--------------------+
So, I can have such data with two related 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 the point of view of my domain, I only care about the Resume entity. I do not want to have a Resume object with its Resume_Translations collection, because I will only have one Resume object with the 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 to Fluent NHibernate is as follows:
public class ResumeMap : ClassMap<Resume> { public ResumeMap() { Table("Resume"); Id(x => x.Id); Map(x => x.IsActive);
I can get what I want from the repository, without any problems, just passing the predicate Id Resume and Language to WHERE I want to.
However, I have some problems setting and updating the values.
My question is: how would I define a mapping that NHibernate Inserts a new record only into the Resume_Translation table instead of updating the record for the current object?
So what I want to achieve is if I have the following entry in my database:
|2 | true | 2 | 'fr' | 'B' | 'bla bla' |
Joining is good for relations between tables, so if I get it in my essence and I change the language and translation, nhibernate does the update, and I can understand it. If I try to add a new object with the same identifier in a different language and translation, nhibernate gives an error that the key already exists, and I also understand it.
So, of course, I am going the wrong way, but if someone can point me to the right decision on how I could achieve the comparison that I want, I would really appreciate it.
Another question, how do you feel about the entity and their translations from a business point of view?
Thank you for your help.
Thomas