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


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

  • 相关阅读:
    Cannot find module 'webpack'
    Failed to read auto-increment value from storage engine
    laravel框架查看执行过的sql语句
    windows与虚拟机共享文件夹设置
    csv导出文件中有html
    特定中文字符串正则匹配
    运动跟踪等算法的解释
    自控力这本书的读后感
    提取肤色信息原理及操作——opencv
    那些年我们排过的序之希尔排序
  • 原文地址:https://www.cnblogs.com/demonyx/p/5336981.html
Copyright © 2020-2023  润新知