Linq distinct record containing keywords

前端 未结 12 1960
醉话见心
醉话见心 2021-02-19 05:09

I need to return a distinct list of records based on a car keywords search like: \"Alfa 147\"

The problem is that, as I have 3 \"Alfa\" cars, it returns 1 + 3 records (i

12条回答
  •  醉话见心
    2021-02-19 05:46

    Try removing the class while select

     var query = (from k in keywordQuery where splitKeywords.Contains(k.Name) 
                            join kac in keywordAdCategoryQuery on k.Id equals kac.Keyword_Id
                            join c in categoryQuery on kac.Category_Id equals c.Id
                            join a in adQuery on kac.Ad_Id equals a.Id
                            select new
                            {
                                Id = c.Id,
                                Name = c.Name,
                                SearchCount = keywordAdCategoryQuery.Where(s => s.Category_Id == c.Id).Where(s => s.Keyword_Id == k.Id).Distinct().Count(),
                                ListController = c.ListController,
                                ListAction = c.ListAction
                            }).Distinct().ToList();
    
            var searchResults = new CategoryListByBeywordsListDto();
    
    
    
    searchResults.CategoryListByKeywordsDetails = (from q in query select new           CategoryListByKeywordsDetailDto
    {
                            Id = q.Id,
                            Name = q.Name,
                            SearchCount = q.SearchCount,
                            ListController = q.ListController,
                            ListAction = q.ListAction
                        }).ToList();
    

提交回复
热议问题