Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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:

alt text

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

like image 584
Pyttroll Avatar asked Nov 03 '09 15:11

Pyttroll


1 Answers

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
                       );
like image 176
Alan Mendelevich Avatar answered Nov 07 '22 06:11

Alan Mendelevich