查询中无法构造实体或复杂类型
List<User> userlist = db.Users
.Include("Department")
.Include("Department.Company")
.Where(x=>x.Id==userID)
.Select(x => new User
{
Department = new Department
{
Company = new Company
{
Phone = x.Department.Company.Phone
}
}
}).ToList();
如果用实体类会报错:查询中无法构造实体或复杂类型
改成代理类,就没有问题了
List<PUser> userlist = db.Users
.Include("Department")
.Include("Department.Company")
.Where(x=>x.Id==userID)
.Select(x => new PUser
{
Department = new PDepartment
{
Company = new PCompany
{
Phone = x.Department.Company.Phone
}
}
}).ToList();