public JsonResult SearchProduct(int page, int pageSize, string key)
{
using (context = new ACETeaEntities())
{
var lstCatalog = context.Drinks.Select(x => new { x.Id_drinks, x.Vie_name, x.Eng_name, x.Id_category, x.Cool, x.Numberoforder, x.Price }).Where(x => x.Id_drinks.Contains(key) || x.Vie_name.Contains(key) || x.Eng_name.Contains(key) || x.Id_category.Contains(key) || x.Numberoforder.ToString() == key || (x.Cool == true ? "Có Lạnh" : "").Contains(key)).ToList();
var data = lstCatalog.Skip((page - 1) * pageSize).Take(pageSize);
int totalRow = lstCatalog.Count();
return Json(new
{
data = data,
total = totalRow,
status = true
}, JsonRequestBehavior.AllowGet);
}
}
I have a search warrant as above. But I can not find the number for the keyword. It will select all numbers containing the number 'key'. And I also can not convert into string to use Contains(key).
Error: System.NotSupportedException: 'LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression.'
Numberoforder : Number of orders (int);
Cool : (bool) Please help me. Thank you!