Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

How can i include more than one include in the query

$
0
0

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


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>