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:
@@ -16,6 +16,10 @@ public record ReadResultViewQuery : IRequest<IEnumerable<ResultViewDto>>
|
|||||||
public long? ActionId { get; init; } = null;
|
public long? ActionId { get; init; } = null;
|
||||||
|
|
||||||
public long? ProfileId { 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>>
|
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)
|
if(request.ProfileId is long profileId)
|
||||||
q = q.Where(rv => rv.ProfileId == 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);
|
var entities = await q.ToListAsync(cancel);
|
||||||
|
|
||||||
if (entities.Count == 0)
|
if (entities.Count == 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user