-
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
LEFT JOIN with GROUP BY: System.InvalidOperationException: Nullable object must have a value. #12355
Labels
area-query
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
customer-reported
punted-for-3.0
type-bug
Milestone
Comments
The generated SQL query: SELECT [order].[Id], [order].[CreationDate], [t].[OrderId], [t].[MaxDate]
FROM [Orders] AS [order]
LEFT JOIN (
SELECT [orderItem].[OrderId], MAX([orderItem].[ExpirationDate]) AS [MaxDate]
FROM [OrderItems] AS [orderItem]
GROUP BY [orderItem].[OrderId]
) AS [t] ON [order].[Id] = [t].[OrderId] |
It starts working if I cast the anonymous class properties to nullable: from order in dbContext.Orders
join maxExpirationDate in
(
from orderItem in dbContext.OrderItems
group orderItem by orderItem.OrderId
into itemsGroup
select new { OrderId = (int?)itemsGroup.Key, MaxExpDate = (DateTime?)itemsGroup.Max(item => item.ExpirationDate)}
) on order.Id equals maxExpirationDate.OrderId into joinedMaxDate
from maxExpirationDate in joinedMaxDate.DefaultIfEmpty()
select new { order.Id, maxExpirationDate }; |
Note for triage: this doesn't fail in L2O. |
@maumar Can you investigate the root cause of this? |
The same exception can be obtained without GroupBy : #12520 |
This works in 3.1 |
smitpatel
added
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
and removed
try-on-latest
labels
Dec 6, 2019
smitpatel
added a commit
that referenced
this issue
Dec 6, 2019
smitpatel
added a commit
that referenced
this issue
Dec 6, 2019
smitpatel
added a commit
that referenced
this issue
Dec 7, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
area-query
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
customer-reported
punted-for-3.0
type-bug
I'm joining a table (LEFT OUTER JOIN) with a subquery having a GROUP BY clause and returning an aggregation function result. If there are no matching rows in the right side table (
NULL
s are fetched), it fails with aInvalidOperationException: Nullable object must have a value.
. Here is the query I'm having problems with:Steps to reproduce
Include a complete code listing (or project/solution) that we can run to reproduce the issue.
Partial code listings, or multiple fragments of code, will slow down our response or cause us to push the issue back to you to provide code to reproduce the issue.
Further technical details
EF Core version: 2.1.0
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Windows 10 1803
IDE: Visual Studio 2017 15.7.3
The text was updated successfully, but these errors were encountered: