Reputation: 331
I have a model "MainCategory". How can I take 3 categories only from my mainCategory?
var mainCategory = _context.MainCategories
.Include(c => c.Categories)
.Skip(0)
.Take(3)
.FirstOrDefault();
Upvotes: 2
Views: 83
Reputation: 4354
EfCore does not support that out of the box. However, the below can be used as a workaround in some specific cases
var mainCategory = _context.MainCategories
.Select(c => new
{
c,
Categories= c.Categories.OrderBy(x => x.CategoryID)
.Skip((PageSize * PageNumber) - PageSize)
.Take(PageSize)
})
.FirstOrDefault();
P.S: DbContext can't track the object anymore. This is the downside of this approach
Upvotes: 1