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


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

  • 相关阅读:
    部署NetCore项目(本文介绍用用IIS部署)
    vs中添加MySql实体集流程
    一文搞定HashMap的实现原理
    二分查找
    hashcode返回值可能为负数
    哈希碰撞与生日攻击
    并发的第二天
    java并发编程-1
    排序的第一天
    并发的第一天
  • 原文地址:https://www.cnblogs.com/demonyx/p/5336981.html
Copyright © 2020-2023  润新知