本地化表和Entity Framework [英] Localized tables and Entity Framework

查看:213
本文介绍了本地化表和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.

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

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

在读值返回,如果名的价值并不在用户的文化存在默认值(值的对象最初是创建)将被使用。
下面的图表演示如何将数据存储在SQL:

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:

我试图映射此架构使用实体框架的对象模型,我M有点困惑,以什么来解决这个问题的最好办法。

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.

时的EF合适呢?我应该用EF4?

Is EF appropriate for this? Should I used EF4?

这EF模型将由.NET RIA服务中使用。

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

谢谢,

皮埃尔 - 伊夫·Troel

Pierre-Yves Troel

推荐答案

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

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.

事情是这样的:

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

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

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