How to convert this IQueryable <Patient> to DbSet <Patient>?

It should be simple, but I worked on the line inside the IF block. Error on this line

"It is not possible to implicitly convert the type 'System.Linq.IQueryable [Patient]' to 'System.Data.Entity.DbSet [Patient]. An explicit conversion exists (do you miss the role?)"

I tried to add many extensions ( AsQueryable() , ToList() , AsEnumerable() , etc.) after .Contains() no avail.

What am I missing here? This project is created using the beta version of MVC 4 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()); } 
+6
source share
2 answers

Declare patients explicitly as IQueryable<Patient>

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

Or call AsQueryable on it:

 var patients = this.db.Patients.AsQueryable(); 
+12
source

You can simply change the type of patients to make this work:

 IQueryable<Patient> patients = this.db.Patients; 
+5
source

Source: https://habr.com/ru/post/915297/


All Articles