這個錯誤出現在我的代碼中......“ICollection”不包含“Any”的定義,并且找不到接受“ICollection”類型的第一個參數的擴展方法“Any”(您是否缺少 using 指令或匯編參考?) // my BooksController.cs Code public ActionResult Index() { var books = db.Books.Include(h => h.BorrowHistories) .Select(b => new BookViewModel { BookId = b.BookId, Author = b.Author, Publisher = b.Publisher, SerialNumber = b.SerialNumber, Title = b.Title, IsAvailable = !b.BorrowHistories.Any(h => h.ReturnDate == null) //Error is coming in this line }).ToList(); return View(books); }我還有一個類名 BookViewModel.cs 有一個函數 public bool IsAvailable。 // my Book.cs using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.ComponentModel.DataAnnotations; using System.Collections; namespace LibraryManagmentSystem.Models { public class Book { public int BookId { get; set; } [Required] public string Title { get; set; } [Required] [Display(Name = "Serial Number")] public string SerialNumber { get; set; } public string Author { get; set; } public string Publisher { get; set; } public ICollection BorrowHistories { get; set; } } }
1 回答

月關寶盒
TA貢獻1772條經驗 獲得超5個贊
我認為你需要將你的書類編輯成這樣:
public ICollection<YourSubClass> BorrowHistories { get; set; }
代替:
public ICollection BorrowHistories { get; set; }
因為 LinQ 需要一個類型才能正常工作。我沒有看到你的 BorrowHistories 模型,所以我不能說是否足夠。
- 1 回答
- 0 關注
- 325 瀏覽
添加回答
舉報
0/150
提交
取消