I have simple method where I retrieve data from database and send it to the View. But in the meantime data need to filtered. I have below code:
public ActionResult Index(string Name, string Manufacturer)
{
var dev = db.Devices;
if(!String.IsNullOrEmpty(Name))
{
dev = dev.Where(w => w.Name.Contains(Name));
}
if(!String.IsNullOrEmpty(Manufacturer))
{
dev = dev.Where(w => w.Manufacturer.Contains(Manufacturer));
}
return View(dev.ToList());
}
but I'm getting this error:
Cannot implicitly convert type 'System.Linq.IQueryable' to 'System.Data.Entity.DbSet'. An explicit conversion exists (are you missing a cast?)
I tried adding cast eg:
(DbSet<Device>)
But didn't helped. Can anyone suggest me how to modify my code?