我有一个部门对象,该对象包含员工列表。如何获得特定员工所在的部门?我有一个通用FindAll
IQueryable<Department> FindAll(params Expression<Func<Department, object>>[] includeProperties)
然后我尝试了
FindAll().Where(x => x.Employee.Any(y => y.Name == name)).FirstOrDefault();
答案 0 :(得分:2)
您想加载相关实体吗?
你可以这样做:
var employee = context.Employee.FirstOrDefault(y=>y.Name==name);
if(employee!=null)
{
context.Entry(employee).Reference("Department").Load();
var deparment = employee.Department;
}