I don’t know to what extent what I have in mind will be done. But I’ll try my luck to find someone here who can explain it to me.
I have following method in my DB repository:
public async Task<IList<BroadcastEntryEntity>> GetByPeriodOfTimeOfProgramAsync(Guid programId, DateTime dateTimeStartUtc,
DateTime dateTimeEndUtc, bool includePrograms = false,
bool includePlayouts = false, bool includeRecords = false)
{
return await Set.Include(broadcastEntry => broadcastEntry.Program)
.Include(broadcastEntry => broadcastEntry.PlayoutInstance)
.Include(broadcastEntry => broadcastEntry.Record)
.ThenInclude(record => record.ContentTags)
.Include(broadcastEntry => broadcastEntry.Record)
.ThenInclude(record => record.ExternalIds)
.Where(item => item.ProgramId == programId &&
item.BroadcastDateTimeUtcStart >= dateTimeStartUtc &&
item.BroadcastDateTimeUtcEnd <= dateTimeEndUtc)
.OrderBy(broadcastEntry => broadcastEntry.BroadcastDateTimeUtcStart)
.ToListAsync();
}
This works great so far. I’m just wondering how I could optionally exclude the includes using the method parameters: includePrograms
, includePlayouts
, includeRecords
?
Is it possible to do something like what the example here suggests (I know it can’t work like that):
public async Task<IList<BroadcastEntryEntity>> GetByPeriodOfTimeOfProgramAsync(Guid programId, DateTime dateTimeStartUtc,
DateTime dateTimeEndUtc, bool includePrograms = false,
bool includePlayouts = false, bool includeRecords = false)
{
if (includePrograms){
// Include the programs
var programInclude = Set.Include(broadcastEntry => broadcastEntry.Program)
}
if (includePlayouts){
// Include the playout instances
var playoutInclude = Set.Include(broadcastEntry => broadcastEntry.PlayoutInstances)
}
if (includeRecords){
// Include the records
var recordInclude = Set.Include(broadcastEntry => broadcastEntry.Record)
.ThenInclude(record => record.ContentTags)
.Include(broadcastEntry => broadcastEntry.Record)
.ThenInclude(record => record.ExternalIds)
}
return await Set.Where(item => item.ProgramId == programId &&
item.BroadcastDateTimeUtcStart >= dateTimeStartUtc &&
item.BroadcastDateTimeUtcEnd <= dateTimeEndUtc)
.OrderBy(broadcastEntry => broadcastEntry.BroadcastDateTimeUtcStart)
.ToListAsync();
}
Or am I on the wrong track here and do something like this completely differently?
I would be very grateful for any advice here.