LINQ to Entities不识别方法'System.String ToString()'方法,并且此方法不能转换为商店表达式。LINQ to Entities不识别方法'System.String ToString()'方法,并且此方法无法转换为存储表达式
public ActionResult PopulateFromDB(string sidx, string sord, int page, int rows)
{
var context = new NerdDinnerEntities();
var jsonData = new
{
total = 1,
page = page,
sord =sord,
records = context.Authors.Count(),
rows = (from n in context.Authors
select new
{ AuthorId = n.AuthorId ,
cell = new string[] { n.AuthorId.ToString(), n.Name.ToString(), n.Location.ToString() }
}).ToList()
};
return Json(jsonData, JsonRequestBehavior.AllowGet);
}
我书面方式ToList或ToArray的是它不工作的错误出现:
public ActionResult PopulateFromDB(string sidx, string sord, int page, int rows)
{
var context = new NerdDinnerEntities();
var jsonData = new
{
total = 1,
page = page,
sord =sord,
records = context.Authors.Count(),
rows = (from n in context.Authors
select new
{ AuthorId = n.AuthorId ,
cell = new string[] { n.AuthorId.ToString(), n.Name.ToString(), n.Location.ToString() }
}).ToList()
};
return Json(jsonData,JsonRequestBehavior.AllowGet);
}
试着用'Convert.ToString'取代'object.ToString' –
感谢您的答复我,但同样的错误是显示转换。 ToString(n.Name)作为所有字段但不变。 – Saurabhbhatt