Localized tables and Entity Framework

前端 未结 2 1734
醉话见心
醉话见心 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
                           );
    

提交回复
热议问题