我想我的結果將我的LINQ查詢到一個列表後獲得對象的List <>,但沒有成功,直到如今。失敗LINQ查詢
This is my action method :
public ActionResult DisplayListOfRolesUser()
{
string currentUserId = User.Identity.GetUserId();//get the id of the logged user
UserDetails userDetails = db.UsersDetails.Where(c => c.identtyUserId == currentUserId)
.FirstOrDefault();
int UsrCompanyId = userDetails.CompanyId;//get the user's company
List<WorkRole> WorkRolesQuery = db.WorkRoles.Where(c => c.CompanyId == UsrCompanyId)
.FirstOrDefault().ToList();//get all the work roles for the compnay.
//List<WorkRole> lst = WorkRolesQuery.ToList();
return View(lst);
}
我嘗試了許多堆棧溢出的答案,但沒有成功。
目前List<WorkRole> WorkRolesQuery = db.WorkRoles.Where(c => c.CompanyId == UsrCompanyId).FirstOrDefault().ToList();
ToList是強調用紅色和它說「WorkRole」不包含「ToList」的定義。
我只是想有WorkRole
對象的列表,所以我可以在我的某種形式的視圖中顯示它們。
有人可以幫忙嗎?
這裏是我的型號還有:
public class WorkRole
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int WorkRoleId { get; set; }
public string RoleName { get; set; }
public string RoleDescription { get; set; }
public int CompanyId { get; set; }
public virtual Company Company { get; set; }
public virtual ICollection<WorkRolesUsersDetails> WorkRolesUsersDetails { get; set; }
}