LINQ to Entities 不識別方法「System.String ToString()」,所以該方法沒法轉換爲存儲表達式。spa
行 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: }