C# 缺少using指令或程序集引用

C# 缺少using指令或程序集引用,c#,asp.net-mvc,C#,Asp.net Mvc,我的代码中出现了此错误。。。。 “ICollection”不包含“Any”的定义 并且没有接受第一个参数的扩展方法“Any” 找不到类型为“ICollection”的。是否缺少 使用指令还是程序集引用 // my BooksController.cs Code public ActionResult Index() { var books = db.Books.Include(h => h.BorrowHistories)

我的代码中出现了此错误。。。。 “ICollection”不包含“Any”的定义 并且没有接受第一个参数的扩展方法“Any” 找不到类型为“ICollection”的。是否缺少 使用指令还是程序集引用

      // 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是可用的

        // 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; }

          }
         }

我认为您需要将book类编辑为这样的内容:

public ICollection<YourSubClass> BorrowHistories { get; set; }

因为LinQ需要一个类型才能正常工作。我看不到您的借阅历史记录模型,所以我不能说它是否足够。

也许,您缺少使用BookController.cs中的System.Linq。我认为Linq作用于类型化集合。必须将.Cast转换为正确的类型才能使用Linq。您也可以将ICollection更改为ICollectioninstead@YeldarKurmangaliyev我用过这个系统。Linq@DennisKuypers请解释一下你想说什么
public ICollection BorrowHistories { get; set; }