-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Aggregate function on owned type fails in EF7 #29201
Comments
var query = context.Books
.GroupBy(post => post.Author.Id, e => new { e, e.Detail })
.Select(grouping => new
{
Author = grouping.Key,
TotalCost = grouping.Sum(post => post.Detail.Price),
}); |
Note from triage: this is the result of a design change in query and cannot easily be fixed. We will document as a breaking change in 7.0. |
Is this a workaround? if it is, it doesn't seem to work on json columns too :( var query = context.Books
.SelectMany(x => x.Histories)
.Where(x => x/*JsonColumn*/.Snapshot /*JsonColumn*/.Published)
.GroupBy(grouping => grouping.Snapshot.PublishDate, e => new { e, e.Snapshot })
.Select(group => EF.Functions.DateDiffDay(group.Key, group.OrderByDescending(a => a.Snapshot.LastPublishDate).FirstOrDefault()!.Snapshot.LastPublishDate)))
.Sum();
|
@smitpatel The workaround query still throws the same exception. |
Exception only happens for owned type since when expanding lambdas over aggregate function, we don't expand owned navigations (which are not expanded by nav expansion). There is no way to expand beforehand, since it is 2nd level lambda. The expansion in subquery form would happen automatically when translating but the issue here is that we end up throwing exception from |
I am not sure what I am doing wrong, below code is throwing the following error. I am using EF Core 8.0.4 QUERY var result = await _dataContext.Parts.Include(x => x.Ac)
.Where(x => x.AcId == acNo)
.GroupBy(x => new { x.AcId, x.Ac.AcName }, y => new { y, y.PartBloDetail })
.Select(x => new
{
AcId = x.Key.AcId,
AcName = x.Key.AcName,
PartCount = x.Count(),
BloCount = new BloCountDto
{
TotalBloCount = x.Count(y => !string.IsNullOrEmpty(y.PartBloDetail.BloName))
}
}).FirstOrDefaultAsync(); MODEL CLASS public class Part : AuditableEntityWithId<int>
{
public int PartNo { get; set; }
public string PartName { get; set; } = default!;
public int AcId { get; set; }
public Ac? Ac { get; set; }
public PartBloDetail? PartBloDetail { get; set; }
}
public class PartBloDetail
{
public string? BloName { get; set; }
}
public class Ac : AuditableEntity
{
public int AcId { get; set; }
public string AcName { get; set; } = default!;
} ERROR
|
@Dwipraj please open a new issue for that. |
Ok, but it seems I am missing something with the var result = await _dataContext.Parts.Include(x => x.Ac)
.Where(x => x.AcId == acNo)
.GroupBy(x => new { x.AcId, x.Ac.AcName }, y => new { y, y.PartBloDetail })
.Select(x => new
{
AcId = x.Key.AcId,
AcName = x.Key.AcName,
PartCount = x.Count(),
BloCount = new BloCountDto
{
TotalBloCount = x.Sum(y => !string.IsNullOrEmpty(y.PartBloDetail.BloName) ? 1 : 0)
}
}).FirstOrDefaultAsync(); Should I open a new issue for that or not? @roji |
Code below works in EF Core 6.0.
The text was updated successfully, but these errors were encountered: