This should be straightforward but I’m getting tripped up on the line inside the IF block. The error on that line is
“Cannot implicitly convert type ‘System.Linq.IQueryable[Patient]’ to
‘System.Data.Entity.DbSet[Patient]’. An explicit conversion exists
(are you missing a cast?)”
I tried appending a variety of extensions (AsQueryable(), ToList(), AsEnumerable(), etc) after .Contains() to no avail.
What am I missing here? This project is build using the MVC 4 Beta and EF4
public ActionResult SearchIndex(string searchString)
{
var patients = this.db.Patients;
if (!String.IsNullOrEmpty(searchString))
{
patients = patients.Where(p => p.LastName.Contains(searchString));
}
return View(patients.ToList());
}
Declare patients explicitly as
IQueryable<Patient>Or call
AsQueryableon it: