Work with IQueryables in AutoMapper #3779
abdollahkahne
started this conversation in
NA
Replies: 2 comments
-
https://docs.automapper.org/en/latest/Queryable-Extensions.html |
Beta Was this translation helpful? Give feedback.
0 replies
-
Yes, after adding |
Beta Was this translation helpful? Give feedback.
0 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.
-
Hi,
consider that I have a query which return
IQueryable<Company>
and I should map it toIQueryable<CompanyDto>
. When I use the AutoMapper, it sends the all-columns query to database and then, after returning the result, it try to apply the requested mapping which is not a good practice considering performance. Does exist any method that support this situation?To clarify my question I send a similar but simple Example:
and
AutoMapper Profile:
Now I have two alternative to make the query:
1- not using AutoMapper as below:
As the following image shows it only request the required columns:

2-Using the AutoMapper
var companiesDTO = _mapper.Map<IQueryable<Company>, IEnumerable<CompanyDto>>(companies); // Altough this work but I am not sure that works performant
and the query that sent to database is the full columns query

Beta Was this translation helpful? Give feedback.
All reactions