LINQ to Entities 不识别方法“System.String ToString()”,因此该方法无法转换为存储表达式。

LINQ to Entities 不识别方法“System.String ToString()”,因此该方法无法转换为存储表达式。

 

行 34:         public ActionResult CreateUser ()
行 35:         {
行 36:             ViewBag.DeptTypes = _dbContext.DepartmentTypes.Select(x => new SelectListItem() { Text = x.Description, Value = x.Id.ToString() }).ToList();
行 37:             return View();
行 38:         }


解决方法:Select前ToList()或ToArray()
行 34:         public ActionResult CreateUser ()
行 35:         {
行 36:             ViewBag.DeptTypes = _dbContext.DepartmentTypes.ToList().Select(x => new SelectListItem() { Text = x.Description, Value = x.Id.ToString() }).ToList();
行 37:             return View();
行 38:         }
posted @ 2013-08-23 12:28  gitran  阅读(345)  评论(0编辑  收藏  举报