Hi,
Could anyone please tell me whats wrong with the below Linq query? It iterate only first sequence 3 times based on CatNo 1. Means, CategoryNoList is 1,2,3, the query returns 3 same rows where CatNo is 1. But it should return 3 rows for each 3 CatNo.
Note: CatName is string and CatNo is int?
using (DefaultConnection dbCon = new DefaultConnection())
{
List<Products> prod = new List<Products>();
var CategoryNoList = DefaultConnection.Products.Where(p => p.CatName == "catname").Select(p => p.CatNo).ToList();
foreach (var catno in CategoryNoList)
{
var ProdList = (from ProdRec in dbCon.Products
where ProdRec.CatName == "catname" && ProdRec.CatNo == catno
select ProdRec).First();
prod.Add(ProdList);
}
return View(prod.ToList());
}