查询中无法构造实体或复杂类型

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();

posted @ 2016-03-30 14:10  严于律己,宽以待人  阅读(406)  评论(1编辑  收藏  举报