public async Task<IEnumerable<Object>> GetBooksAsync(int pageNumber, int length = 0)
{
// get all the books needed to send to user
return await _context.Bookss
.Skip((pageNumber - 1) * _options.ItemsPerPage)
.Take(_options.ItemsPerPage)
.Include(book => book.BookAuthorss)
.ThenInclude(bookAuthor => bookAuthor.Author)
.Select(books => new
{
books.Id,
books.Title,
Authors = books.BookAuthorss.Select(author => new { Id = author.Author.Id, author.Author.Name }),
booksCategories = books.BooksCategories.Select(category => new { Id = category.Category.Id, category.Category.CategoryName })
})
.ToListAsync();
}
Returning Data From Tables Having Many To Many Relationships C# LINQ .NET (Dot Net)
