I have search functionality on my page, where I use multiple strings to filter search results. In this case, best way is using IQueryable, but I have to send my search result in view as List.
So problem comes when I try to convert my result .ToList(). I get System.NotSupportedException here, saing "LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression."
What can I do in this situation?
public ActionResult Index(string name, string lastName, string bloodGrade)
{
if (Request.IsAjaxRequest())
{
IQueryable<User> result = db.Users;
if (name != null)
{
result = result.Where(s => s.Name.Contains(name));
}
if (lastName != null)
{
result = result.Where(s => s.Lastname.Contains(lastName));
}
if (bloodGrade != null)
{
result = result.Where(s => s.BloodGrade.ToString() == bloodGrade);
}
return PartialView("_Wall", result.ToList());
}
return View(db.Users.ToList());
}