开发者

Entity Framework and Multi Language Databases

I was just wondering if there was any best practices when using Entity Framework with multi-language databases? My database design for handling this is to have a separate table for all of my translations:

[Product Table]
ProductID     开发者_如何学PythonPK
NameId        FK
DescriptionId FK

[Translation Table]
TextId        PK
LanguageId
TranslationText

I am happy to go along with this approach but I was wondering if Entity Framework has any features that can help with this? It would nice to be able to have a Product entity object, give it a language and then access the name and description fields direct and in the correct language.

Thanks, Nick


As somebody has asked if I ever got a resolution for this, I thought I would add my solution to this:

I changed the DB schema so instead of having one table for all translations for different text types, I have a separate 'Text' table e.g.

[Product Table]
ProductID           PK
ProductName         In master language for reference
ProductDesription   In master language for reference
<other product fields>

[ProductText Table]
ProductID             PK
LanguageId            PK
ProductName           Language-Specific name
ProductDescription    Language-Specific description

I have a number of these 'text' tables for local language translations for each entity type that needs it.

Then if I need to access the localised data from EF, I use the following (example is to get the German text):

Product product = db.Products.Where(m => m.ProductId == 1);
ProductName germanProductName = product.ProductNames(m => m.LanguageId == "de");

Hope this helps


Entity Framework is a general-purpose ORM, it doesn't offer any domain-specific features. Multilingual support for a particular application is a domain-specific problem.

Are you looking for something specific?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜