错误:LINQ to Entities中仅支持无参数构造函数和初始值设定项

时间:2017-06-05 05:57:48

标签: linq

以下是我的代码。我正在努力获得公司名单以及每家公司下的员工名单。但是下面的代码是抛出错误

  

LINQ to Entities中仅支持无参数构造函数和初始值设定项。

请帮忙。

public class Company {
    public int CompID { get; set; }
    public string CompanyName { get; set; }
    public List<Employees> EmplList { get; set; }
}

public class Employees {
    public int EMPID { get; set; }
    public string EMPNAME { get; set; }
}

var empllist = (from c in Db.Company select new Company {
    CompID = c.ID,
    CompanyName = c.Name,
    EmplList = new List<Employees> (
        from e in Db.Employee
        where c.ID == e.ID
        select new Employees {
            EMPID = e.ID,
            EMPNAME = e.Name
        })
    }).ToList();

1 个答案:

答案 0 :(得分:0)

尝试代码

http://localhost:5555/grid/register