亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

缺少 using 指令或程序集引用

缺少 using 指令或程序集引用

C#
墨色風雨 2021-10-09 16:39:23
這個錯誤出現在我的代碼中......“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 模型,所以我不能說是否足夠。


查看完整回答
反對 回復 2021-10-09
  • 1 回答
  • 0 關注
  • 325 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號