zoukankan      html  css  js  c++  java
  • 查询中无法构造实体或复杂类型

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

  • 相关阅读:
    SDN2017 第四次作业
    SDN2017 第三次实验作业
    软件工程实践2017 个人作业——软件工程实践总结作业
    sdn2017 第三次作业
    Golang 探索对Goroutine的控制方法
    SDN2017 第二次实验作业
    SDN2017 第二次作业
    Redis在游戏服务器中的应用
    手机游戏开发
    手机游戏开发
  • 原文地址:https://www.cnblogs.com/demonyx/p/5336981.html
Copyright © 2011-2022 走看看