Here below I am using lambda expression in LINQ Includes for 1 level, to fetch a list of customers using three entities, the main one is for all Customers and has only 2 properties Id and bool: IsCompany, the second one has only those that are companies, and the third one has only those that are individuals. The below code was working using .Net Core 2.2, when I updated to 3.0 it stopped working, and most I could find are solutions for multi level such as Include -> ThenIclude that cannot work here. And version 3.0 breaking changes don't mention this case.
public async Task<ActionResult<IEnumerable<CustomersListVM>>> GetCustomers()
{
List<CustomersListVM> customerList = await _context.Customers
.Include(p => p.Company.Name)
.Include(p => p.Individual.Name)
.Select(p => new CustomersListVM
{
Id = p.Id,
CustomerId = p.CustomerId,
Name = p.IsCompany == true ? p.Company.Name : p.Individual.LastName + ' ' + p.Individual.FirstName
}).ToListAsync();
return customerList;
}
Any idea ?
Include("Full.Path.ToChild")
and it works fine.Name
in the Include clauses.