EF Core query
#4021
Replies: 2 comments 2 replies
-
Check the execution plan. Compare it bettween the two versions. If it's the same, it's EF Core. |
Beta Was this translation helpful? Give feedback.
0 replies
-
The generated queries are different. However, I suspect that's more due to improvements in EF Core. .NET Framework + EF Core 3.1 + AutoMapper 10.1:SELECT TOP(1) [c].[Id], ..., [t4].[Foo] AS [Foo]
FROM [dbo].[Settings] AS [c]
LEFT JOIN (
SELECT [c5].[Id], [c5].[Foo]
FROM [dbo].[Settings] AS [c5]
WHERE [c5].[Foo] IS NOT NULL
) AS [t4] ON [c].[Id] = [t4].[Id]
WHERE [c].[Id] = @__id_0 .NET 6 + EF Core 6.0.6 + AutoMapper 11.0.1:Original query:SELECT TOP(1) [c].[Id], ..., [c].[Foo] AS [Foo]
FROM [dbo].[Settings] AS [c]
WHERE [c].[Id] = @__id_0 Fixed query:SELECT TOP(1) [c].[Id], ... COALESCE([c].[Foo], CAST(0 AS bit)) AS [Foo]
FROM [dbo].[Settings] AS [c]
WHERE [c].[Id] = @__id_0 |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have an existing .NET Framework 4.8 WebAPI project using AutoMapper v10.1.1 and EF Core 3.1, which I am upgrading to .NET 6, AutoMapper 11.0.1, and EF Core 6.0.6.
The source model contains an owned entity:
The target model flattens the data:
I then use
ProjectTo
to load a specific DTO instance:In the .NET Framework version, this works as expected. If none of the owned entity columns are set, the
SettingsDto.Foo
property is set tofalse
.In the .NET 6 version, if none of the owned entity columns are set, I get an exception:
To resolve the problem, I had to cast the
MapFrom
property tobool?
, as mentioned on StackOverflow:I couldn't see this change in behaviour documented anywhere. And I'm not entirely sure whether it's AutoMapper or EF Core which has caused it.
Beta Was this translation helpful? Give feedback.
All reactions