views:

224

answers:

2

Hi, I'm not sure how to use composite key.

My Categories table has CategoryId (PK,FK), LanguageId (PK,FK), CategoryName

CategoryId | LanguageId | CategoryName
1          | 1          | Car
1          | 2          | Auto
1          | 3          | Automobile
etc.

I'm following this design

The default action looks like

//
// GET: /Category/Edit/5

public ActionResult Edit(int id)
{
    return View();
}

and ActionLink

<%= Html.ActionLink("Edit", "Edit", new { id= item.CategoryId }) %>

Should I use something like

<%= Html.ActionLink("Edit", "Edit", new { id= (item.CategoryId + "-" + item.LanguageId) }) %>

so the url is

/Category/Edit/5-5

and

//
// GET: /Category/Edit/5-5

public ActionResult Edit(string id)
{
    // parse id

    return View();
}

or change the route to something like

/Category/Edit/5/5

Or there is some better way?

A: 

Yes, there is a better way. You can also determine the user's language and culture from the request to determine which record from your database to use. And I wouldn't come up with a random scheme like 1 = english 2 = german. Use the standard culture identifiers.

Will
You are right. I understand that I can use ie. website.com/en/... But what if I need to see all languages for CategoryName at once in my administration?
nubm
A: 

Well, it's easier than I thought :-) Just put 2 parameters into RouteValues in ActionLink so it generates a query string.

<%= Html.ActionLink("Edit", "Edit", new { id= item.CategoryId, lang= item.LanguageId }) %>

The url will be Category/Edit/1?lang=3

So it's more about routing than anything else in my question. More on this

nubm