开发者

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 this

var 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 Int

Language

LangID | LangName

1 | English

2 | French

Here is my database structure.

Category

CatID | IsActive

1 | True

2 | True

3 | True

CategoryText

CatID | CatName | LangID

1 | Car |1

1 | Auto |2

2 | Chat |2

3 | Plane | 1

3 | Avion | 2

Thanks


string 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;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜