I’m working on an .Net MVC3 project. I have the following code which runs 2 queries on the same table. The second query is depended on the results of the first. How can i rewrite this to use a single query (with nested query) and assign the results to my viewmodel?
public ViewResult Category(string id)
{
var viewModel = new ProductCategoryNavigation();
viewModel.category = db.Category.Single(c=>c.NavigationId==id);
viewModel.subCategories = db.Category.Where(i => i.ParentId == category.Id);
return View(viewModel);
}
1 Answer