You can map this with the <join> element
(http://nhforge.org/doc/nh/en/index.html#mapping-declaration-join) -
however, that's not necessarily a good approach.  I'm assuming that
there's a "current locale", e.g. for the current user?  I'm also a
little suspicious of the table structure - it feels to me as if there
should perhaps be a Locale entity encapsulating the LangCode and any
other related stuff, otherwise this is being repeated in multiple rows
in multiple tables which feels like a smell.

 

That said, would the following suggestion work for you:

 

1.  Create a Locale entity as above, and a table to match

2.  Create a one-to-many relationship from Country & City to Locale with
an appropriate protected collection mapping (ISet seems logical)

3.  Add a filter to that
(http://nhforge.org/doc/nh/en/index.html#objectstate-filters)
relationship which uses the current locale as a parameter and so results
in exactly one element returned

4.  Create public functions/properties which expose the single element
in this collection

 

The filter can be initialised globally by your IoC container.

 

Example (omiting important stuff like ctor's & null checks):

 

class Country {

                public int Id { get; protected set; }

                protected ISet<LocaleData> Locales { get; set; }

                public string LocalName { get { return
Locales.First().Name; } set { Locales.First().Name = value; } }

}

 

Re. City.CountryId, my suggestion would be to access that via the the
Country association rather than exposing it directly.

 

/Pete

 

From: [email protected] [mailto:[email protected]] On
Behalf Of Patrick Sannes
Sent: 06 April 2013 13:25
To: [email protected]
Subject: [nhusers] Mapping localization tables in Nhibernate

 

Im building a localized application. All data needs to be available in
different languages. As a storage model I try to use Nhibernate because
of the better performance over Entity Framework. I store a root node in
the database to get a unique Id for an entity and then I have a second
table with the child nodes per language (the locale table).

My database table looks like:

Country
   Int Id;
Country_Locale
   Int Id;
   Int CountryId;
   String LangCode;
   String Name;
 
City
   Int Id;
   Int CountryId;
City_Locale
   Int Id;
   Int CityId;
   String LangCode;
   String Name;

My prefered Entities would look like

Country
  Int Id (from Coutry table)
  String LangCode (from locale table)
  String Name (from locale table)
  IList<City> Cities (Referenced to City entity)
City
  Int Id (From City table)
  String LangCode (from locale table)
  String Name (from locale table)
  Country Country (Referenced to Country entity)
  Int CountryId (From country table)

I realize that I cannot map the above, but it is a sort of the structure
I would prefer. How could I do this mapping or are there other
suggestions.

-- 
You received this message because you are subscribed to the Google
Groups "nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nhusers?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nhusers?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to