Guest User

Untitled

a guest
Jul 16th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. // my BooksController.cs Code
  2. public ActionResult Index()
  3. {
  4. var books = db.Books.Include(h => h.BorrowHistories)
  5. .Select(b => new BookViewModel
  6. {
  7. BookId = b.BookId,
  8. Author = b.Author,
  9. Publisher = b.Publisher,
  10. SerialNumber = b.SerialNumber,
  11. Title = b.Title,
  12. IsAvailable = !b.BorrowHistories.Any(h => h.ReturnDate == null) //Error is coming in this line
  13. }).ToList();
  14. return View(books);
  15. }
  16.  
  17. // my Book.cs
  18. using System;
  19. using System.Collections.Generic;
  20. using System.Linq;
  21. using System.Web;
  22. using System.ComponentModel.DataAnnotations;
  23. using System.Collections;
  24.  
  25. namespace LibraryManagmentSystem.Models
  26. {
  27. public class Book
  28. {
  29. public int BookId { get; set; }
  30. [Required]
  31. public string Title { get; set; }
  32. [Required]
  33. [Display(Name = "Serial Number")]
  34. public string SerialNumber { get; set; }
  35. public string Author { get; set; }
  36. public string Publisher { get; set; }
  37. public ICollection BorrowHistories { get; set; }
  38.  
  39. }
  40. }
  41.  
  42. public ICollection<YourSubClass> BorrowHistories { get; set; }
  43.  
  44. public ICollection BorrowHistories { get; set; }
Add Comment
Please, Sign In to add comment