[英]Conditional Include in ASP.NET
哇,很簡單,
IIncludableQueryable<ProductEntity, object?> dbSet = _context.Set<ProductEntity>().Include(i => i.Media);
if (dto.ShowCategories.IsTrue()) dbSet = dbSet.Include(i => i.Categories);
if (dto.ShowComments.IsTrue())
dbSet = dbSet.Include(i => i.Comments!.Where(x => x.ParentId == null))
.ThenInclude(x => x.Children)!
.ThenInclude(x => x.Media);
if (dto.ShowLocation.IsTrue()) dbSet = dbSet.Include(i => i.Locations);
if (dto.ShowForms.IsTrue()) dbSet = dbSet.Include(i => i.Forms);
if (dto.ShowMedia.IsTrue()) dbSet = dbSet.Include(i => i.Media);
if (dto.ShowReports.IsTrue()) dbSet = dbSet.Include(i => i.Reports);
if (dto.ShowTeams.IsTrue()) dbSet = dbSet.Include(i => i.Teams)!.ThenInclude(x => x.User).ThenInclude(x => x.Media);
if (dto.ShowVotes.IsTrue()) dbSet = dbSet.Include(i => i.Votes);
if (dto.ShowVoteFields.IsTrue()) dbSet = dbSet.Include(i => i.VoteFields);
if (dto.ShowCreator.IsTrue()) dbSet = dbSet.Include(i => i.User).ThenInclude(x => x!.Media);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.