我試圖在我的視圖中顯示用戶的下拉列表。下面是我用在我的控制器方法的代碼:使用LINQ創建SelectListItem的集合
var users = _usersRepository.Users.Select(u => new SelectListItem
{
Text = u.FirstName + " " + u.LastName,
Value = u.UserID.ToString()
}
return View(new MyViewModel { Users = users });
我得到一個錯誤試圖UserID
轉換爲字符串:
LINQ到實體無法識別方法「系統。 String ToString()'方法,並且此方法不能轉換爲存儲表達式。
如何從我的實體創建一個SelectListItem
的集合?
看看這個:http://stackoverflow.com/questions/5899683/linq-to-entities-does-not-recognize -the-method-system-string-tostring-method – 2012-03-21 20:14:45