I am trying to replace a view with a stored procedure to search results based on a keyword. But when I pass a keyword it throws an error
The result of a query cannot be enumerated more than once
but it works fine if the keyword is left empty. Below is my method to get search results. Can anyone provide any suggestions on how to enumerate the results in this case?
public IEnumerable <BrandNameToIngredient> GetBrandNameToIngMapResults(string Keyword)
{
IEnumerable<BrandNameToIngredient> lstBrandNametoIng = from map in DB.USP_BRANDNAME_INGREDIENT_MAP()
select new BrandNameToIngredient
{
IngredientBrandNameMapID=map.INGREDIENT_PRODUCT_MAP_ID,
BrandName = map.FDA_BRAND_NAME, //From Table 1
PFCName = map.PFC_DESC==null?"":map.PFC_DESC, //From Table 1
IngredientName = map.INGREDIENT_NAME, //From Table 2
HCIngredientName = map.HC_INGREDIENT_NAME, //From Table 2
KeywordfromPage = Keyword
};
if (!string.IsNullOrEmpty(Keyword))
{
lstBrandNametoIng = lstBrandNametoIng.Where(x => x.BrandName.ToLower().Contains(x.KeywordfromPage.ToLower()) //Able to get result
|| x.PFCName.ToLower().Contains(x.KeywordfromPage.ToLower()) //Able to get result
|| x.IngredientName.ToLower().Contains(x.KeywordfromPage.ToLower()) //Error Here
|| x.HCIngredientName.ToLower().Contains(x.KeywordfromPage.ToLower())); //Error Here
}
return lstBrandNametoIng;
}