Not able to return JsonResult

前端 未结 2 1805
暖寄归人
暖寄归人 2021-02-09 20:05

The following query is working successfully.

var tabs = (
                from r in db.TabMasters
                orderby r.colID
                select new { r.         


        
2条回答
  •  礼貌的吻别
    2021-02-09 20:26

    It's because it's adding to the LINQ query that is your tabs IQueryable. That is then trying to turn the LINQ expression into a SQL query and the provider doesn't support projecting arrays.

    You can either change the assignment of the tabs variable's LINQ expression to use ToList to materialize the DB results right then and there, or you can add .AsEnumerable() to the LINQ expression assigned to the rows field of the anonymous type that is your JsonResult. AsEnumerable will demote the IQueryable to an IEnumerable which will prevent your second LINQ query from trying to be added to the DB query and just make it a LINQ-to-objects call like it needs to be.

提交回复
热议问题