Add options to include Action/Profile in ResultView queries

Added IncludeAction and IncludeProfile properties to ReadResultViewQuery, allowing callers to control eager loading of related Action and Profile entities. Updated handler to conditionally include these navigation properties based on the new flags for more flexible data retrieval.
This commit is contained in:
2026-03-02 13:57:14 +01:00
parent 776813d05d
commit ec119a3045

View File

@@ -16,6 +16,10 @@ public record ReadResultViewQuery : IRequest<IEnumerable<ResultViewDto>>
public long? ActionId { get; init; } = null;
public long? ProfileId { get; init; } = null;
public bool IncludeAction { get; init; } = true;
public bool IncludeProfile { get; init; } = false;
}
public class ReadResultViewQueryHandler(IRepository<ResultView> repo, IMapper mapper) : IRequestHandler<ReadResultViewQuery, IEnumerable<ResultViewDto>>
@@ -33,6 +37,12 @@ public class ReadResultViewQueryHandler(IRepository<ResultView> repo, IMapper ma
if(request.ProfileId is long profileId)
q = q.Where(rv => rv.ProfileId == profileId);
if(request.IncludeAction)
q = q.Include(rv => rv.Action);
if(request.IncludeProfile)
q = q.Include(rv => rv.Profile);
var entities = await q.ToListAsync(cancel);
if (entities.Count == 0)