I have got problem with LINQ query. In table towar I would like to get Kategorie.Nazwa
Example in sql: SELECT Kategorie.Nazwa FROM Towar INNER JOIN Kategorie ON Towar.Id_kat = Kategorie.Id_kat

Here is my problem .Where(p => category == null || p.Id_kat == category) I need name of category but I have got number. I need this p.Id_kat = SELECT Kategorie.Nazwa FROM Towar INNER JOIN Kategorie ON Towar.Id_kat = Kategorie.Id_kat I using EntityFramework DbContext.
SomeView viewModel = new SomeView
{
Towar = repository.Towar
.Where(p => category == null || p.Id_kat == category)
.OrderBy(p => p.Id_tow)
.Skip((page - 1) * PageSize)
.Take(PageSize),
Kategorie = re.Kategorie
.OrderBy(p => p.Id_kat),
PagingInfo = new PagingInfo
{
CurrentPage = page,
ItemsPerPage = PageSize,
TotalItems = repository.Towar.Count()
},
CurrentCategory = category
};
return View(viewModel);
}
If you setup a foreign key between Towar and Kategories, then you won’t have to do a join. You can use the POCO classes reference to the Kategory class and the power of Entity Framework. Here is an example of what I mean with a test:
Notice how the Towar class has a property to the Kategory class.