All - I have got two questions regarding the repository pattern used in the Ardalis CleanArchitecture.
With ListAsync how can I project to only a few fields not to all of them? Example: if I have 20+ fields in the table & I need only 3 fields to fetch from it. I see in the template the repository uses "ToListAsync()" ef api, however this executes a "Select * " in the SQL Server database table. I wanted only to fetch 3 fields which is part of my DTO.
With specification pattern I see an option to select required fields. That means when using specification I can project to a DTO. Where is the ideal place to put these kinds of dtos? Under specifications folder itself?
Any help on these would be very much appreciated. Thanks a bunch!
Template Repo: https://github.com/ardalis/CleanArchitecture
The easiest way I thought of is using AutoMapper. AutoMapper has an extension method
IQueryable.ProjectTo<>
. You can implementRepositoryBase<>
and inherit that toEfRepository<>
instead of inheritingRepositoryBase<>
directly.ApplicationRepository class