LINQ

时间:2016-07-01 10:36:38

标签: c# linq

 (from chapter in Chapters
        join userChapter in UserChapters on chapter.Id equals userChapter.ChapterId
        join pub in Publications on chapter.Id equals pub.ChapterId into P 
        from publication in P.DefaultIfEmpty()
        where userChapter.UserId == 9
        group new
                           {
                               PubID = publication.Id,
                               Logo = chapter.Logo
                           } by new { chapter.Id, chapter.Name} into x
                           orderby x.Key.Name
        select new 
       {
           Id = x.Key.Id,
           chapterName = x.Key.Name,
           PublicationCount = x.Count(z => z.PubID > 0),
           Logo = x.Max(z=>z.Logo)
       }
)

在上面的查询中,“chapter.Logo”的类型为byte[],当我尝试执行此查询时,我收到以下错误。

  

聚合操作中不支持“System.Data.Linq.Binary”类型 - LINQ。

2 个答案:

答案 0 :(得分:0)

    (from chapter in Chapters
    join userChapter in UserChapters on chapter.Id equals    userChapter.ChapterId
    join pub in Publications on chapter.Id equals pub.ChapterId into P 
    from publication in P.DefaultIfEmpty()
    where userChapter.UserId == 9
    group new
                       {
                           PubID = publication.Id,
                           Logo = chapter.Logo
                       } by new { chapter.Id, chapter.Name} into x
                       orderby x.Key.Name
    select new 
   {
       Id = x.Key.Id,
       chapterName = x.Key.Name,
       Logo = x.Max(z=>z.Logo.Count())
   }

答案 1 :(得分:0)

    (from chapter in Chapters
    join userChapter in UserChapters on chapter.Id equals    userChapter.ChapterId
    join pub in Publications on chapter.Id equals pub.ChapterId into P 
    from pub in P.DefaultIfEmpty()
    where userChapter.UserId == 9
    group pub by new { chapter.Id, chapter.Name,chapter.Logo,pub.Id} into x
                       orderby x.Key.Name
    select new 
   {
       Id = x.Key.Id,
       chapterName = x.Key.Name,
       Logo = x.Key.Logo,
   PublicationCount=x.Count()
   }