I have the following model
public class Book { [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int BookId { get; set; } [Required] [StringLength(10,MinimumLength =3, ErrorMessage ="ISBN must be between 3 and 10 characters")] public string Isbn { get; set; } [Required] [MaxLength(200, ErrorMessage = "Title cannot be more than 200 characters")] public string Title { get; set; } public DateTime? DatePublished { get; set; } [ForeignKey("CategoryId")] public int CategoryId { get; set; } public Category Category { get; set; } [ForeignKey("AuthorId")] public int AuthorId { get; set; } public Author Author { get; set; } public ICollection<Review> Reviews { get; set; }
In my sql how can I include <Category > object along with the given sql. Please help
public ICollection<Book> GetBooks() { return _db.Books.Include(a => a.Author).OrderBy(b => b.Title).ToList(); }