Asp.net MVC 2 How customize my Model in Framework Entity. Issue For multilang app
Here is a multilang table design. Is it possible to add a method for my CategoryText model to give me the CatName for a specific langID. LangID will be chosen by the customer and set in Session variable.
EXAMPLE :I would like to get the category name like thisvar a = _db.Categories.Single(a=> a.AreaTypeID == 2);
string CatName = a.CategoryTexts.GetCatName();
Languages
LangID PK
LangName nvarchar(100)
Category
CatID Pk开发者_高级运维IsActive Bit
CategoryText
CatID FK CatName nvarchar(200) LangID IntLanguage
LangID | LangName 1 | English 2 | French Here is my database structure.Category
CatID | IsActive 1 | True 2 | True 3 | TrueCategoryText
CatID | CatName | LangID 1 | Car |1 1 | Auto |2 2 | Chat |2 3 | Plane | 1 3 | Avion | 2 Thanksstring CatName = a.CategoryTexts.
Single(ct => ct.LangID == (int)Session["LangID"]).CatName;
public string GetCatName(Area a)
{
return a.CategoryTexts.
Single(ct => ct.LangID == (int)Session["LangID"]).CatName;
}
精彩评论