c# Build Error with LINQ syntax in Controller

后端 未结 2 1969
独厮守ぢ
独厮守ぢ 2021-01-21 08:44

Hi folks I have the following error on line 11 in this controller code :

    public JsonResult GetChartData_IncidentsBySiteStatus(string SiteTypeId, string searc         


        
2条回答
  •  再見小時候
    2021-01-21 09:20

    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 sitesQry = _db.Sites;
    

    or you can call the .CopyToDataTable extension method that is exposed by Linq.

    sitesQry = _db.Sites.CopyToDataTable();
    

提交回复
热议问题