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:         }
原文地址:https://www.cnblogs.com/gitran/p/3277263.html