本地化表和实体框架 [英] Localized tables and Entity Framework

查看:156
本文介绍了本地化表和实体框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



假设你有一个可以创建动物的应用程序,如果用户是英文的动物的名称属性的值将在UI中输入为猫,而将以法语输入聊天。



动物文化表将包含指向父表中相同动物的2条记录。



读取值时,如果用户文化中不存在名称的值将使用默认值(该对象最初创建的值)。
下图显示了数据如何存储在SQL中:





我试图将该模式映射到使用实体框架的对象模型对于处理这个问题的最好办法有点困惑。



EF是否适合?我应该用EF4吗?



这个EF模型将被.NET RIA服务使用。



谢谢,



Pierre-Yves Troel

解决方案

我在类似情况下所做的是创建一个视图LocalizedAnimals是2表结构的平面表示,并为该视图创建了一个EF模型。所以当我需要显示法语动物数据时,我会过滤这些LocalizedAnimals,并且具有很好的简单对象列表。



这样的东西:

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


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.

The animal culture table would contain 2 records pointing to the same animal in the parent table.

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:

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? Should I used EF4?

This EF model will be used by .NET RIA Services.

Thanks,

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. So when I need to display say French animal data I would filter those LocalizedAnimals and have nice simple object list as a result.

Something like this:

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

这篇关于本地化表和实体框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆