Querying distinct columns across rows filtering by another column

entity-framework entity-framework-core linq linq-to-entities sql

Popular Answer

 PreviousSubcategories =
          from c in dbContext.Categories
             let posts = 
             from p in a.Posts p in dbContext.Posts
             where p.RoleTitle == roleTitle
             where (c.Id == p.Domain1.CategoryId
             || c.Id == p.Domain2.CategoryId
             || c.Id == p.Domain3.CategoryId
             || c.Id == p.Domain4.CategoryId
             || c.Id == p.Domain5.CategoryId
             orderby p.CreatedOn descending 
             select new Domain[]
                   {
                     p.Domain1,
                     p.Domain2,
                     p.Domain3,
                     p.Domain4,
                     p.Domain5
                   }
            where posts.Any()
            select new DomainViewModelDto
                  {
                      SubcategoryId = (int)c.Id,
                      SubcategoryName = c.Name,
                      LatestExperienceLevelsApplied = new LatestExperienceLevelsApplied
                      {
                          IsExperienceLevel1Applied = (bool)posts.First().Where(d => d.CategoryId == c.Id).First().IsExperienceLevel1Applied,
                          IsExperienceLevel2Applied = (bool)posts.First().Where(d => d.CategoryId == c.Id).First().IsExperienceLevel2Applied,
                          IsExperienceLevel3Applied = (bool)posts.First().Where(d => d.CategoryId == c.Id).First().IsExperienceLevel3Applied,
                          IsExperienceLevel4Applied = (bool)posts.First().Where(d => d.CategoryId == c.Id).First().IsExperienceLevel4Applied,
                          IsExperienceLevel5Applied = (bool)posts.First().Where(d => d.CategoryId == c.Id).First().IsExperienceLevel5Applied,
                          IsExperienceLevel6Applied = (bool)posts.First().Where(d => d.CategoryId == c.Id).First().IsExperienceLevel6Applied,
                      }


                  }
1
3/31/2020 8:58:09 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow