Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 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);
- }
- // 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; }
- }
- }
- public ICollection<YourSubClass> BorrowHistories { get; set; }
- public ICollection BorrowHistories { get; set; }
Add Comment
Please, Sign In to add comment