简体   繁体   English

本地化表和实体框架

[英]Localized tables and Entity Framework

I have a scenario where I need to localized values of objects in my database. 我有一个场景,我需要在我的数据库中的对象的本地化值。

Let's say you have an application that can create animals, if the user is english the value of the "Name" property of an animal would be entered as "Cat" in the UI whereas it would be entered as "Chat" in french. 假设您有一个可以创建动物的应用程序,如果用户是英语,动物的“名称”属性的值将在UI中输入为“猫”,而它将以法语输入为“聊天”。

The animal culture table would contain 2 records pointing to the same animal in the parent table. 动物培养表将包含2个指向父表中相同动物的记录。

When reading values back, if the value of "Name" does not exist in the user culture the default value (value the object was originally created with) would be used. 当读回值时,如果用户文化中不存在“名称”的值,则将使用默认值(最初创建对象的值)。 The following diagrams demonstrate how the data is stored in SQL: 下图演示了如何在SQL中存储数据:

替代文字

I'm trying to map this schema to an object model using the Entity Framework, I'm a bit confused as to what the best way to approach the problem. 我正在尝试使用实体框架将此模式映射到对象模型,我对于解决问题的最佳方法有点困惑。

Is EF appropriate for this? EF适合这个吗? Should I used EF4? 我应该使用EF4吗?

This EF model will be used by .NET RIA Services. .NET RIA Services将使用此EF模型。

Thanks, 谢谢,

Pierre-Yves Troel Pierre-Yves Troel

What I did in a similar situation is created a view say LocalizedAnimals which is a flat representation of that 2 table structure and created an EF model for that view. 我在类似情况下所做的是创建一个视图说LocalizedAnimals,它是该2表结构的平面表示,并为该视图创建了EF模型。 So when I need to display say French animal data I would filter those LocalizedAnimals and have nice simple object list as a result. 因此,当我需要显示说法国动物数据时,我会过滤那些LocalizedAnimals并因此得到漂亮的简单对象列表。

Something like this: 像这样的东西:

var localizedAnimals = myContext.LocalizedAnimals.Where(
                           p => p.CultureName == Thread.CurrentThread.CurrentUICulture.Name
                       );

I'm not sure you'd want to do this in the database. 我不确定你是否想在数据库中这样做。 I think it would be more sensible to use a configuration file or resource that defines Culture-specific names. 我认为使用定义特定于文化的名称的配置文件或资源会更明智。

You might also check Microsoft's documentation on internationalization and localization . 您还可以查看Microsoft有关国际化和本地化的文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM