The third option looks great. The hibernation mapping is displayed, but not the database schema β if this is not enough, then I will draw it here:
dictionary ---------- ID: int - identity name: nvarchar(255) phrase ------ dictionary_id:int (fkey dictionary.ID) culture_id:int (LCID) phrase:nvarchar(255) - this is the default size - seems too small
According to this blog entry 255 is the default string length for String values. To overcome the short string length in the text of a phrase, you can change the <element> to
<element column="phrase" type="String" length="4001"></element>
To use this in your domain model, you add the PhraseDictionary property to your entity where you want to translate the text. For instance. title property or decription property.
I think the article describes a great approach, and exactly the one that I would go for.
EDIT: In response to the comments, make the length less than 4001 if you know that the maximum maximum size is less than this, as this will usually be faster. In addition, NHibernate will lazily retrieve a collection, but it can receive all items at once. You can customize the profile to determine if it has performance implications. (If you have only a few languages, then I doubt that you will see the difference.) If you have many languages ββ(say 50+), it may be useful to create custom properties to get localized text. They will issue requests for specially needed text. More importantly, you can get all the text for a given object in one request, and not each property of the localized text as a separate request.
Please note that this extra effort is only necessary if profiling gives you reason to worry about performance. Most likely, the implementation in the article as it will will function more than adequately.
source share