I need to store localized entities in a database (for instance a Product, which has a Name, which is different in English and Danish). There are several well-known ways to do this, for instance having some sort of a resource table containing the values of the localized columns.
However, this does not seem to be very easy to fit into an ORM, when I want to retrieve an instance of the Product class in the English language and expect the value of the Name property to be English.
I don't want to reinvent the wheel, and I think this is a problem that must be very common. Does any ORM support entity localization out-of-the box ?
Since I am on the Microsoft stack, and obvious choice for an ORM would be Entity Framework 4. Are there any features in EF4 to support this ?
AFAIK EF4 does not provide anything like this.
Dmitri Maximov has written a good series of post covering implementation of localization for DataObjects.Net, the info there may be helpful for you even if you're using (or going to use) any other framework:
I have the exact same problem (localize content, MS stack, ORM...) and for the moment I go with Resource/ResourceValue tables. I use Linq-to-SQL with PLINQO templates that I've slightly tuned to generate auto localized Properties in my entities.
The template detects foreign keys to the Resource table and create an appropriate column.
For example if I have a Product Table with an int NameID
FK column, it will create a string Name
Property on my Product class returning the appropriate value depending on the current Thread culture.
The cons are:
I found this question looking after a "best practice" solution, but it I havn't found one yet.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With