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(),

                               }
                           };       
4

1 回答 1

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()
   }
}
于 2013-10-21T11:04:57.220 回答