What is HotChocolate.Data.AutoMapper? #6735
Replies: 2 comments 3 replies
-
Seems like there is no public repo for this yet. According to the NuGet package explorer it's basically common extensions for AutoMapper and IQueryable. Example member from the package xml:
|
Beta Was this translation helpful? Give feedback.
-
The reason you'd use this is because of the select before where problem. Basically, if you're using DTOs and not your actual database mappings (you should be) then the only way that EF Core can match your query is by projecting into (i.e. select) and then doing the filtering on that projection. This can cause row locks and also can break indexes in lots of cases. AutoMapper is relatively unique in that it has .AsDataSource() which allows you to have it use the mappings for your tables and the dto and reverse that to map the where on the DTO to the where on the table so that you get where then select (i.e. where then ProjectTo) This prevents the row locking issue and the indexes that won't run thus killing perf. If you're using Automapper and not using AsDataSource() in other scenarios for this use case, you should be. It's possibly the most under documented and under appreciated part of AutoMapper. Basically what that method is doing is AsDataSource() behind the scenes but they've ripped it out so that it can do it in the right spot in the graphQL pipline. |
Beta Was this translation helpful? Give feedback.
-
Hello,
We use AutoMapper in our HotChocolate server by injecting
IMapper
into our resolvers and usingProjectTo<TDest>(_mapper.ConfigurationProvider)
against EF Core IQueryables, which is working well for us.I came across https://www.nuget.org/packages/HotChocolate.Data.AutoMapper/ by chance, but I can't find any documentation on what the package does and whether we should be using it?
Beta Was this translation helpful? Give feedback.
All reactions