通常,当我使用 LINQ to SQL 时,我可以使用 Count() 来获取返回的记录数。但是,在这种情况下,Count() 方法不可用,就好像它没有为对象定义一样。我不确定为什么会这样。这是代码:
IQueryable departments;
if (role == "ADMIN")
{
departments =
db.Departments.Select(d => new {d.DepartmentID, FullName = d.Division.DivisionName + ": " + d.DepartmentName})
.OrderBy(d => d.FullName);
}
else
{
departments =
db.J_DeptAdmins.Where(jda => jda.AdminUserID == userID)
.Select(d => new {d.DepartmentID, FullName = d.Department.Division.DivisionName + ": " + d.Department.DepartmentName})
.OrderBy(d => d.FullName);
if (departments.Count() > 0) //Error is here
{
drpDepartment.Style.Add("display", "none");
lblDisplayDepartment.Style.Add("display", "none");
}
}