开发者

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 E开发者_开发知识库nglish.

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:

  • 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.


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.


Maybe you have to look further, I would use NHibernate, and an interceptor to catch the load of an entity and do the localization of the entity, based on the current culture of the application and some way of store the localized strings.

Some resources:

http://elegantcode.com/2008/05/15/implementing-nhibernate-interceptors/

http://knol.google.com/k/fabio-maulo/nhibernate-chapter-11/1nr4enxv3dpeq/14#

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜