Best way to fetch data from localized database

会有一股神秘感。 提交于 2019-12-23 05:19:50

问题


I created table structure to make statuses localized in database:

Status {StatusId, Value} -- Value in this table is status value in default language
StatusTranslation {StatusId, Language, TrasnlationValue} -- StatusId and Language are combined key

But I am having trouble to make this work in entity framework.
When default languege it is easy Status.ToList() but when I need translation I pass to the get method de-CH but I can't return translated Status.
What is the best way to map this using entity framework?
I thought that some of my methods work for this situation but in the end I find they are not.
This is objects in code:

public class Status 
    {
        public int StatusId{ get; set; }
        public string Value{ get; set; }
        public virtual ICollection<StatusTranslation > StatusTranslations { get; set; }
    }
public class StatusTranslation 
    {
        public int StatusId{ get; set; }
        public string Language{ get; set; }
        public string TrasnlationValue{ get; set; }

        public virtual Status Status { get; set; }
    }



UPDATE

var statuses = from c in context.Statuses
           join t in context.StatusTranslations
               on c.StatusId equals t.StatusId
           where t.Language == language

var statuses = from t in context.StatusTranslations
           where t.Language == language
           select t.Status; 

Both of thees return me Status in default form (default language)
Return parameter should be IEnumerable<Status> meybe this is not possible.

So I can return earthier IEnumerable<Status> or IEnumerable<StatusTranslation> but then this can't be one function or there is a hope?

来源:https://stackoverflow.com/questions/24753245/best-way-to-fetch-data-from-localized-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!