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>
IQueryable<Patient> patients = this.db.Patients;
Or call AsQueryable
on it:
var patients = this.db.Patients.AsQueryable();
You can just change the type of patients
to make this work:
IQueryable<Patient> patients = this.db.Patients;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With