我想我的结果将我的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; }
}