C# 如何在MVC5中返回列表-代码优先

C# 如何在MVC5中返回列表-代码优先,c#,jquery,asp.net-mvc,linq,asp.net-mvc-5,C#,Jquery,Asp.net Mvc,Linq,Asp.net Mvc 5,我需要帮助返回一个列表。我想使用jQueryGridMVC返回分页、搜索和网格,但出错了。这是我的模型: namespace PedidosOnline.Models { public class JqueryGrid { [Key] public int ID { get; set; } public string sNombre { get; set; } } } public class JqueryGridMod

我需要帮助返回一个列表。我想使用jQueryGridMVC返回分页、搜索和网格,但出错了。这是我的模型:

namespace PedidosOnline.Models
{
    public class JqueryGrid
    {
        [Key]
        public int ID { get; set; }

        public string sNombre { get; set; }
    }
}

public class JqueryGridModel
{
    private ApplicationDbContext db = new ApplicationDbContext();
    public List<JqueryGrid> GetPlayers(int? page, int? limit, string sortBy, string direction, string searchString, out int total)
    {
        List<JqueryGrid> all = db.JqueryGrids.ToList();
        //string sql = "Select * from JqueryGrid";

        var getJqueryGridToReturn = all.Select(S => new { ID = S.ID, sNombre = S.sNombre });

        total = all.Count();
        var records = (from p in db.JqueryGrids
                       select new JqueryGrid
                       {
                           ID = p.ID,
                           sNombre = p.sNombre
                       }).AsQueryable();

        if (!string.IsNullOrWhiteSpace(searchString))
        {
            records = records.Where(p => p.sNombre.Contains(searchString));
        }

        if (!string.IsNullOrEmpty(sortBy) && !string.IsNullOrEmpty(direction))
        {
            if (direction.Trim().ToLower() == "asc")
            {
                records = SortHelper.OrderBy(records, sortBy);
            }
            else
            {
                records = SortHelper.OrderByDescending(records, sortBy);
            }
        }

        if (page.HasValue && limit.HasValue)
        {
            int start = (page.Value - 1) * limit.Value;
            records = records.Skip(start).Take(limit.Value);
        }

        return records.ToList();
    }
namespace.online.Models
{
公共类JqueryGrid
{
[关键]
公共int ID{get;set;}
公共字符串sNombre{get;set;}
}
}
公共类JqueryGridModel
{
私有ApplicationDbContext db=新ApplicationDbContext();
公共列表GetPlayers(整数页、整数限制、字符串排序、字符串方向、字符串搜索字符串、输出整数总计)
{
List all=db.JqueryGrids.ToList();
//string sql=“从JqueryGrid中选择*”;
var getJqueryGridToReturn=all.Select(S=>new{ID=S.ID,sNombre=S.sNombre});
total=all.Count();
var记录=(从db.JqueryGrids中的p开始)
选择new JqueryGrid
{
ID=p.ID,
sNombre=p.sNombre
}).AsQueryable();
如果(!string.IsNullOrWhiteSpace(searchString))
{
记录=记录。其中(p=>p.sNombre.Contains(searchString));
}
如果(!string.IsNullOrEmpty(sortBy)和&!string.IsNullOrEmpty(direction))
{
如果(方向修剪().ToLower()=“asc”)
{
记录=SortHelper.OrderBy(记录,sortBy);
}
其他的
{
记录=排序器.OrderByDescending(记录,排序比);
}
}
if(page.HasValue&&limit.HasValue)
{
int start=(page.Value-1)*limit.Value;
记录=记录。跳过(开始)。获取(限制。值);
}
返回记录。ToList();
}
错误是:

无法在LINQ to Entities查询返回列表中构造实体或复杂类型

例如: