Hi folks I have the following error on line 11 in this controller code :
public JsonResult GetChartData_IncidentsBySiteStatus(string SiteTypeId, string searc
You are trying to assign a base class instance to a sub class instance.
Instead of
var sitesQry = _db.Sites;
try using
IQueryable<Site> sitesQry = _db.Sites;
While @Eranga 's solution may work, I feel as though there are more options and a better explanation available.
Firstly, the reason that you cannot assign the value is because you are trying to assign and implementation of an interface to a concrete type. THis cannot be done because you have no idea what could be implementing that interface, and this means that the it cannot be assigned to something that has a concrete type.
There are multiple options for this. You can do as @Eranga suggests and create a new variable
IQueryable<Site> sitesQry = _db.Sites;
or you can call the .CopyToDataTable extension method that is exposed by Linq.
sitesQry = _db.Sites.CopyToDataTable();