不识别方法“System.String ToString()”,因此该方法无法转换为
场景:LINQ to Entities 不识别方法“System.String ToString(System.String)”,因此该方法无法转换为存储表达式
LINQ to Entities 不识别方法“System.String ToString(System.String)”,因此该方法无法转换为存储表达式。
该怎么改呢?
------解决方案--------------------
newsList.Select
-〉
newsList.ToList().Select
------解决方案--------------------
你又没作任何筛选,就不存在这方面的问题了,转换成本地集合再select
------解决方案--------------------
用这个方法: SqlFunctions.DateName
http://msdn.microsoft.com/en-us/library/dd487164(v=vs.110).aspx
LINQ to Entities 不识别方法“System.String ToString(System.String)”,因此该方法无法转换为存储表达式。
public ActionResult GetNewsList()
{
var newsList = _newsRepository.GetNewsList();
var newsViewList = newsList.Select(news => new NewsViewModel()
{
Id = news.Id,
Title = news.Title,
Content = news.Content,
CategoryName = news.Category.Name,
PublishDate = news.PublishDate.ToString("yyyy-MM-DD HH:mm:ss"),
UpdateDate = news.UpdateDate.ToString("yyyy-MM-DD HH:mm:ss"),
IsActived = news.IsActived ? "是" : "否"
});
return Json(newsViewList, JsonRequestBehavior.AllowGet);
}
该怎么改呢?
------解决方案--------------------
newsList.Select
-〉
newsList.ToList().Select
------解决方案--------------------
你又没作任何筛选,就不存在这方面的问题了,转换成本地集合再select
------解决方案--------------------
用这个方法: SqlFunctions.DateName
http://msdn.microsoft.com/en-us/library/dd487164(v=vs.110).aspx