这个错误出现在我的代码中......“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; }
}
}
月关宝盒
相关分类