Closed Neme12 closed 10 months ago
There are several different factors here but main thing is
Where(x => x.Localization.CourseId != null && x.Localization.LanguageCode != null)
Any property in key being null means key is null so you would need to verify that each property is non-null.@Neme12 - You should rewrite the query as suggested work-around in point 2 above. We cannot change the behavior back to working query in 3.1 as it was a bug which made it work (and probably gave correct results, but that may not be always correct)
Notes for triage
Discussed in triage and the conclusion is to throw a better exception message for this case.
we now translate this scenario, producing the following sql:
SELECT [c].[Id], [t0].[CourseId], [t0].[LanguageCode]
FROM [Courses] AS [c]
LEFT JOIN (
SELECT [t].[CourseId], [t].[LanguageCode]
FROM (
SELECT [c1].[CourseId], [c1].[LanguageCode], ROW_NUMBER() OVER(PARTITION BY [c1].[CourseId] ORDER BY [c1].[CourseId], [c1].[LanguageCode]) AS [row]
FROM [CourseLocalizations] AS [c1]
WHERE [c1].[LanguageCode] = N'en-US'
) AS [t]
WHERE [t].[row] <= 1
) AS [t0] ON [c].[Id] = [t0].[CourseId]
WHERE EXISTS (
SELECT 1
FROM [CourseLocalizations] AS [c0]
WHERE [c].[Id] = [c0].[CourseId] AND [c0].[LanguageCode] = N'en-US')
Steps to reproduce
Start with this project file and a C# file:
This works properly in EF Core 3.1. And it seems like the problem is that
CourseLocalization
has composite primary key (which makes this look really similar to https://github.com/dotnet/efcore/issues/23401, which was fixed in 5.0.1. I hope it's not a more widespread issue across EF Core 😕)I found a workaround to instead use
Where(x => x.Localization.CourseId != null)
(which generates a compiler warning though).Include provider and version information
EF Core version: 5.0.1 Database provider: Microsoft.EntityFrameworkCore.SqlServer Target framework: .NET 5.0 Operating system: Windows 10 Version 1909 IDE: Visual Studio 16.9.0 Preview 2.0