有两三个表:员工Employee、部门Department、员工部门关联:EmployeeDepartment
其中EmployeeDepartment表有三个字段:id(自增)、eid、did
员工有多条关联部门的数据,想取出关联id最大的那条,应该如何查询?
我现有的查询是这样的:
Employee employee = (from e in db.Employees.Include("EmployeeDepartments") where e.EmployeeId == 1001 select e).First();
根据要查询的ID做OrderBY。用FirstOrDefault取值
员工数据已指定e.EmployeeId == 1001,只有一条,现在是想对导航属性里的值进行排序,不知道怎么操作。。。
已经在员工表建立了导航 public virtual Department Department { get; set; }
查询:var employee=db.Employees.Include(u=>u.Department).Find(u=>u.EmployeeId == 1001).OrderBy(u=>u.Department.id);
我的导航属性是这样的:
public virtual ICollection<EmployeeDepartment> EmployeeDepartments { get; set; }
所以不知道怎么写。
Employee employee = (from e in db.Employees.Include("EmployeeDepartments")
where e.EmployeeId == id
orderby e.EmployeeDepartments.@#(@#……&@(
select e).First();
@Badcode: 把导航改下就行了