我有我的dto
例如:
public class CustomerDto
{
public string Name {get;set;}
public List<DepartmentDto> Departments {get;set;}
}
public class DepartmentDto
{
public string Name {get;set;}
}
我使用ef核心的选择查询:
var data = db.Customers.Select(x => new CustomerDto
{
Name = x.Name,
Departments = x.Departments.Select(e => new DepartmentDto
{
Name = e.Name
})
}).ToList();
执行查询后,如果我的部门列表为null
,则需要创建一个默认值,例如:
没有部门以property
名称记录