Is it possible to control eager loading of child objects.
If I had a parent class that has 20,000 child objects and I only wanted to retrieve a subset of those child objects is it possible?
How would I write the query to do that if it is?
For Example:
I have an Entity called Book which has a number of related Reviews:
public class Book {
public int BookId { get; set; }
public string BookName { get; set; }
public ICollection<Review> Reviews { get; set; }
}
public class Review {
public int ReviewId { get; set; }
public int Score { get; set; }
public Book Book { get; set; }
}
I want to do something like:
var bookWithFirstTwentyReviews = db.Books.Where(b => b.BookId == 1).Include("Reviews").FirstOrDefault();
But I only want to include 20 reviews, not all 20,000