Localized tables and Entity Framework

前端 未结 2 1735
醉话见心
醉话见心 2021-02-08 15:27

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 valu

相关标签:
2条回答
  • 2021-02-08 15:51

    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
                           );
    
    0 讨论(0)
  • 2021-02-08 15:58

    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.

    0 讨论(0)
提交回复
热议问题