2013-10-21 71 views
1

寫第二個列表的正確語法是什麼? bookid和其他字段不能識別列表裏面的另一個列表中選擇

var bookssublist = from bookdetails in bookslist 
          join bookcategories in _context.BookCategories 
          on bookdetails.BookId equals bookcategories.BookId 
          where bookcategories.CategoryId==CategoryId  
          select new BookBasicInfo { 
           count = bookcount, 
           BookInfo = new List<BookInfo>() 
           {          
            BookId = bookdetails.BookId, 
            BookTitle = bookdetails.Title, 
            Images = bookdetails.ThumbnailImagePath, 
            PublishDate = bookdetails.PublishedDate, 
            AuthorList = bookdetails.BookAuthors.Select(q => q.Author.Author1).ToList(), 
            CategoryList =bookdetails.BookCategories.Select(q=>q.Category.CategoryName).ToList(), 

           } 
          };  
+1

hmmm也許你應該看一下'GroupBy'的方向.. –

回答

0

您正在以錯誤的方式使用集合初始值設定項。實際上,您忘記將BookInfo類型的對象傳遞給初始值設定項。

BookInfo = new List<BookInfo>() 
{ 
    new BookInfo() 
    { 
     BookId = bookdetails.BookId, 
     BookTitle = bookdetails.Title, 
     Images = bookdetails.ThumbnailImagePath, 
     PublishDate = bookdetails.PublishedDate, 
     AuthorList = bookdetails.BookAuthors.Select(q => q.Author.Author1).ToList(), 
     CategoryList =bookdetails.BookCategories.Select(q=>q.Category.CategoryName).ToList() 
    } 
} 
相關問題