Can I map the first child in a collection efficiently with AutoMapper & EF Core? #3943
stevendarby
started this conversation in
NA
Replies: 1 comment 4 replies
-
Check the execution plan. That looks good to me. You can set |
Beta Was this translation helpful? Give feedback.
4 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 would like to project the first child in a collection to another type with AutoMapper & EF, however my first attempt at this results in SQL which performs a sub-query for each property I'm selecting from it, plus an extra sub-query to see if it exists or not.
Another attempt, where I manually map the collection to my type and then do the FirstOrDefault() - the SQL for this is better, selecting from Address only once.
Is there a way to achieve something like this with AutoMapper, so I don't need to do the manual part?
Thanks
Example code (AutoMapper 11.0.1, EF Core 6.0.3)
First query SQL
Second query SQL
Beta Was this translation helpful? Give feedback.
All reactions