简体   繁体   English

缺少使用指令或程序集引用

[英]missing using directive or an assembly reference

This error is coming in my code.... 'ICollection' does not contain a definition for 'Any' and no extension method 'Any' accepting a first argument of type 'ICollection' could be found (are you missing a using directive or an assembly reference?) 此错误即将出现在我的代码中。...“ ICollection”不包含“ Any”的定义,也找不到找不到接受“ ICollection”类型的第一个参数的扩展方法“ Any”组装参考?)

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

I have one more class name BookViewModel.cs having a function public bool IsAvailable. 我还有一个类名称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; }

          }
         }

I think you need to edit your book class to something like that: 我认为您需要将您的书本课编辑为类似的内容:

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

instead of: 代替:

public ICollection BorrowHistories { get; set; }

Because LinQ need a type to work correctly. 因为LinQ需要一种类型才能正常工作。 I not see your BorrowHistories model, so i can't say if is enought. 我看不到您的BorrowHistories模型,所以我不能说是否足够。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM