问题
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