Код: Выделить всё
public partial class Child : Entity, IAggregateRoot
{
public Lrp Lrp { get; set; }
public int LrpId { get; set; }
public Country Country { get; set; }
public int CountryId { get; set; }
public Product Product { get; set; }
public int? ProductId { get; set; }
}
public class Product {
public int Id { get; set; }
public string Name { get; set; }
}
public class Lrp {
public int Id { get; set; }
public string Name { get; set; }
}
public class Product {
public int Id { get; set; }
public string Name { get; set; }
}
Код: Выделить всё
public class LrpReportDTO
{
public int Id { get; set; }
public FunderDto Funder { get; set;
public ProductDto Product { get; se
public LrpDto Lrp { get; set; }
public EnumValueDto Status { get; s
public int Count { get; set; }
}
public class FunderDto
{
public int? Id { get; set; }
public string Name { get; set; }
}
public class ProductDto
{
public int? Id { get; set; }
public string Name { get; set; }
}
public class LrpDto
{
public int? Id { get; set; }
public string Name { get; set; }
}
public class EnumValueDto
{
public string Value { get; set; }
public string Name { get; set; }
}
Код: Выделить всё
public async Task GetGroupedLrpReportData(Expression filter, CancellationToken cancellationToken)
{
return await DbContext.Set()
.Where(filter)
.GroupBy(c => new { c.LrpId, c.CountryId, c.FunderId })
.Select(group => new LrpReportDTO
{
Id = group.Key.LrpId,
Funder = new FunderDto
{
Id = group.Key.FunderId,
Name = group.First().Funder.Name
},
Product = new ProductDto
{
Id = group.First().Product.Id,
Name = group.First().Product.Name
},
Lrp = new LrpDto
{
Id = group.Key.LrpId,
Name = group.First().Lrp.Name
},
Status = group.First().Status != null
? new EnumValueDto
{
Value = group.First().Status.ToString(),
Name = group.First().Status.ToString()
}
: null,
Count = group.Sum(x => x.ChildSupporterLinks.Count)
})
.ToListAsync(cancellationToken);
}
Код: Выделить всё
Expression filter = c => c.ChildSupporterLinks.Any(link => link.DateCreated
Подробнее здесь: [url]https://stackoverflow.com/questions/79248173/groupby-problem-in-net-3-1-first-could-not-be-translated-either-rewrite-th[/url]
Мобильная версия