This took me some time to figure out since documentation for Fluent NHibernate is still a little scarce. Let’s say we have an entity “ActivityType” which has an icon and a name, but the name is stored for each language so we have a one to many relationship. This relationship is not only modelled in the entity “ActivityType” but also in several others. The translation is modelled in the “LocalizedEntity” class. As illustrated in the class diagram below:
The DB is illustrated in the next diagram, to make it easy the tables have a different name compared to the entity diagram :p.
The mapping for the “Language” entity is pretty straightforward. The mapping for the “ActivityType” and its localizations was a bigger challenge since I got lost in all the delegates after the Component method.
public class LanuageMapping : ClassMap<Language> { public LanuageMapping() { Id(x => x.Id); Map(x => x.Name); WithTable("[7de_Languages]"); } } public class ActivityTypeMapping : ClassMap<ActivityType> { public ActivityTypeMapping() { WithTable("[7de_EventTypes]"); Id(activityType => activityType.Id); Map(activityType => activityType.IconName); HasMany<LocalizedEntity>(activityType => activityType.Descriptions) .WithTableName("[7de_LocalizedEventTypes]") .Component(description => { description.References<Language>(desc => desc.Language) .CanNotBeNull(); description.Map(desc => desc.Localization) .CanNotBeNull(); }); } } |
Hi, i was mapping a similar model, but the problem is that, using an analogy with your example it says that LocalizedEntity is not mapped.
This worked at the time of writing this post. Haven’t checked it out recently, will add it on my todo list. Sorry I can’t be of any more help at the moment.
You are right, i had another problem in the mapping, its works fine