10

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

Community
  • 1
  • 1
Pyttroll
  • 861
  • 7
  • 6
  • 2
    Do you need to have multiple languages appear in the application at the same time, or would it be only a single language at a time? – Jon Seigel Nov 03 '09 at 16:26
  • What it the relation between your question and the "AD" you put in the end of it ?. Anyway look at this question here http://stackoverflow.com/questions/2272026 – Wahid Bitar Jan 27 '11 at 10:30

2 Answers2

5

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
                       );
Alan Mendelevich
  • 3,591
  • 4
  • 32
  • 50
-1

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.

gaustin
  • 278
  • 2
  • 7
  • 7
    Resources are more dedicated to stores static values than dynamic ones, like in this case. Animal is a definition of an entity that you don't know how many values (instances) will has. In this case the better approach (not the only one) is the suggested by Pyttroll – Lester Apr 22 '10 at 20:27
  • 1
    Long time ago but you "have" to use a database for user/admin generated content. In terms of generation, resource files are only of use pre-production because they require compilation. You could try dynamically generating them but then you'll get into locking issues and a whole host of issues already solved by a DBMS. – rism Jun 07 '14 at 12:05