Как заменить одним лаконичным выражением на Linq следующие строчки:
foreach (Company company in companies)
{
List<CheckPoint> checkPoints = await _context.CheckPoints
.Where(cp => cp.CompanyId == company.Id).ToListAsync();
}
Модели:
public class CheckPoint
{
[Key]
public ulong Id { get; private set; }
[Column("Name", TypeName = "nvarchar(MAX)")]
public string Name { get; private set; }
[Column("CompanyId", TypeName = "decimal(20, 0)")]
public ulong CompanyId { get; private set; }
public Company? Company { get; private set; }
public CheckPoint(string name)
{
Name = name;
CompanyId = default;
Company = default;
}
public class Company
{
[Key]
public ulong Id { get; private set; }
[Column("FullName", TypeName = "nvarchar(MAX)")]
public string FullName { get; private set; }
public List<User>? Users { get; private set; }
public List<CheckPoint>? CheckPoints { get; private set; }
public Company(string fullName)
{
Id = default;
FullName = fullName;
Users = new List<User>();
CheckPoints = new List<CheckPoint>();
}
}