AUA Framework Training — Episode 16

Query Projection with ProjectTo

Optimizing Database Queries and Entity-to-DTO Projections using ProjectTo in AUA Services

Watch Video on YouTube

Models and Mapping Efficiency

Mapping complex software system entities into Data Transfer Objects (DTOs) or custom View Models is a fundamental practice. The AUA framework streamlines this architecture by allowing developers to leverage conversion functions and fetch DTOs directly from the database using powerful mechanisms like ProjectTo right inside services.

Direct Database Projection

Within AUA services, you can seamlessly utilize ProjectTo to transform database query results straight into target structures, optimizing execution performance and memory footprint.

Performance Advantage: Reduces unnecessary overhead by projecting directly at the database query level.

Integrated Mapping Suite

Working hand-in-hand with IMapFrom and IHaveCustomMappings, ProjectTo provides a unified, robust framework ecosystem for handling simple to complex field and collection mappings.

Clean Architecture: Keeps your data transfer logic clean, modular, and decoupled from raw entity layers.

3. Executing Projections in Service Layer (ConvertTo & ProjectTo)

AppUserService.cs
public class AppUserService : GenericEntityService<AppUser, AppUserDto>, IAppUserService
{
    public AppUserService(IUnitOfWork unitOfWork) : base(unitOfWork) { }

    // Example 1: ConvertTo Execution
    public IEnumerable<TestMappingVm> GetTestMappingVmsWithConvertTo()
    {
        var query = GetAll().Where(p => p.IsActive);

        return query
            .ConvertTo<TestMappingVm>(MapperInstance)
            .ToList();
    }

    // Example 2: Direct Database Projection using ProjectTo
    public IEnumerable<TestMappingVm> GetTestMappingVmsWithProjectTo()
    {
        var query = GetAll().Where(p => p.IsActive);

        return MapperInstance
            .ProjectTo<TestMappingVm>(query)
            .ToList();
    }
}
“
”
"If you think good architecture is expensive, try bad architecture."
AUA Framework Philosophy

Official Channels & Community

Connect with the AUA Framework ecosystem.

Episode 16 Completed WebAuthorize and User Access