What is the best way to convert this IQueryablePatient> to a DbSetPatient>?

.net-4.0 asp.net-mvc entity-framework

Question

This should be simple, however the line within the IF block is where I'm having trouble. The mistake is on that line,

"Cannot implicitly convert type 'System.Linq.IQueryable[Patient]' to 'System.Data.Entity.DbSet[Patient]'. An explicit conversion exists (are you missing a cast?)"

I experimented with adding several extensions (AsQueryable() , ToList() , AsEnumerable() , etc) following.Contains() all in vain

What do I not see here? This project was created with the help of EF4 and MVC 4 Beta.

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());

}
1
6
5/9/2012 3:32:03 PM

Accepted Answer

Indicate patients' status asIQueryable<Patient>

IQueryable<Patient> patients = this.db.Patients;

OR dialAsQueryable on it:

var patients = this.db.Patients.AsQueryable();
12
5/9/2012 3:21:48 PM

Popular Answer

Simply altering the kind ofpatients To make this function:

IQueryable<Patient> patients = this.db.Patients;


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow