1

2 番目のリストを記述する正しい構文は何ですか? 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 に答える