Cześć napisałem takie wyrażenie:
var payload = await db.Categories.Include(x=>x.Topics).ThenInclude(x=>x.Answers).Select(x => new CategoryList
{
Id = x.Id,
Name = x.Name,
Description = x.Description,
TopicsCount = (uint)x.Topics.Count,
AnswersCount = (uint)x.Topics.Sum(x=>x.Answers.Count)
}).ToListAsync();
i mam taki błąd:
Microsoft.Data.SqlClient.SqlException (0x80131904): Cannot perform an aggregate function on an expression containing an aggregate or a subquery.
at Microsoft.Data.SqlClient.SqlCommand.<>c.<ExecuteDbDataReaderAsync>b__164_0(Task`1 result)
at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
Wiecie może dlaczego mam taki bład znaczy rozumiem że winą jest to:
AnswersCount = (uint)x.Topics.Sum(x=>x.Answers.Count)
ale kurcze jak inaczej mogę obliczyć ta sumę ? :)