i tried this:
For wrapping City with it's selected LocalLanguage
public class CityLocolized
{
public City City { get; set; }
public String LocalName { get; set; }
}
Here, we chose the either
default so with if else no join,
else chose from CityCulture table
string lang = System.Threading.Thread.CurrentThread.CurrentUICulture.Name;
List<CityLocolized> citiesLocalized = null;
if (lang == "en") // which is default in db
{
citiesLocalized = (from c in fke.Cities
select new CityLocolized
{
City = c,
LocalName = c.Name
}
).ToList();
}
else // for other languages
{
citiesLocalized = (from c in fke.Cities
join cc in fke.CityCultures
on c.Id equals cc.CityId
where cc.LangId == lang
select new CityLocolized
{
City = c,
LocalName = cc.LocalName
}).ToList();
}
and this one for passing View:
ViewData["CitiesLocolized"] = new SelectList(citiesLocalized, "City.Id", "LocalName");
finally at view:
<%:Html.DropDownListFor(model => model.CityId, ViewData["CitiesLocolized"] as SelectList)%>
i think this is it.
Also instead of if else which seems weird, this this below with some join cost:
cityLocos = (from c in fke.Cities
join cc in fke.CityCultures
on c.Id equals cc.CityId
where cc.LangId == lang
select new CityLoco
{
City = c,
LocalName = lang == "en" ? c.Name : cc.LocalName // "en" being default language
}).ToList();
moguzalp