以下查询已成功运行.
var tabs = ( from r in db.TabMasters orderby r.colID select new { r.colID,r.FirstName,r.LastName }) .Skip(rows * (page - 1)).Take(rows);
现在我想要返回JsonResult
var jsonData = new { total = (int)Math.Ceiling((float)totalRecords / (float)rows),page = page,records = totalRecords,rows = (from r in tabs select new { id = r.colID,cell = new string[] { r.FirstName,r.LastName } }).ToArray() }; return Json(jsonData,JsonRequestBehavior.AllowGet);
但它会给我一个错误,如:
无法在查询结果中初始化数组类型’System.String []’.请考虑使用’System.Collections.Generic.List`1 [System.String]’.
我该怎么做才能得到预期的结果?
解决方法
我怀疑它就像使用AsEnumerable()将最后一部分推入进程内查询一样简单:
var jsonData = new { total = (int)Math.Ceiling((float)totalRecords / (float)rows),rows = (from r in tabs.AsEnumerable() select new { id = r.colID,cell = new[] { r.FirstName,r.LastName } } ).ToArray() }; return Json(jsonData,JsonRequestBehavior.AllowGet);
var rows = tabs.AsEnumerable() .Select(r => new { id = r.colID,r.LastName }) .ToArray(); var jsonData = new { total = (int)Math.Ceiling((float)totalRecords / (float)rows),page,rows };
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。