以下是我的示例数据。两家公司有两名员工。
List<Company> companies = new List<Company>
{
new Company
{
Name = "ABC Company",
Address = "No.1 St. USA",
Employees = new List<Employee> { new Employee { Name = "John", Age = 30 }, new Employee { Name = "David", Age = 20 } }
},
new Company
{
Name = "DEF Company",
Address = "No.2 St. USA",
Employees = new List<Employee> { new Employee { Name = "Michael", Age = 22 }, new Employee { Name = "Jason", Age = 27 } }
}
};
我尝试使用以下语法检索所有员工:
var employees = companies.Select(c => c.Employees).ToList();
然而,它给了我
当前上下文中不存在名称“员工”
当我在运行时观看它时。我的预期结果是List<Employee>
拥有所有 4 名员工。任何建议将不胜感激。