Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does any .NET ORM support localized entities out-of-the-box?

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 ?

like image 709
driis Avatar asked Feb 11 '10 11:02

driis


2 Answers

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:

  • Localization support, part 1. Theory
  • Localization support, part 2. Domain modeling
  • Localization support, part 3. CRUD operations
  • Localization support, part 4. Queries - a bit outdated, I'd better recommend you to view code of working localization sample.
like image 175
Alex Yakunin Avatar answered Nov 03 '22 01:11

Alex Yakunin


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:

  • complexity for INSERTS / UPDATES (must play with 3 tables, but Linq2Sql make it not so difficult)
  • browsing tables in SQL Management is painfull because Text columns are just foreign keys

I found this question looking after a "best practice" solution, but it I havn't found one yet.

like image 40
Guillaume86 Avatar answered Nov 03 '22 01:11

Guillaume86