C
C#3y ago
Batuhan

❔ Include several include within get method

Helllo, i got an issue about including more than many entity relation to getAsync method. The reason is that causing a problem my getAsync method consist only one IIncludableQueryable parameter. But i have to include 3 different relation. Here is my getAsync method and my include method. GetAsync Method == >
Task<T?> GetAsync(Expression<Func<T, bool>> predicate,
Func<IQueryable<T>, IIncludableQueryable<T, object>>? include = null);
Task<T?> GetAsync(Expression<Func<T, bool>> predicate,
Func<IQueryable<T>, IIncludableQueryable<T, object>>? include = null);
Include Method ===>
public async Task<BookGetByIdDto> Handle(GetByIdBookQuery request, CancellationToken cancellationToken)
{
await _rules.BookShouldBeExistWhenRequested(request.Id);
//todo && x.Include(x=>x.Author) && x.Include(x=>x.BookPublishers) find solution for the inclue more than many entity
var book = await _bookRepository.GetAsync(x=>x.Id == request.Id ,include:x=>
x.Include(x=>x.Category) &&
x.Include(x=>x.Author) &&
x.Include(x=>x.BookPublishers));
var mappedBook = _mapper.Map<BookGetByIdDto>(book);
return mappedBook;
}
public async Task<BookGetByIdDto> Handle(GetByIdBookQuery request, CancellationToken cancellationToken)
{
await _rules.BookShouldBeExistWhenRequested(request.Id);
//todo && x.Include(x=>x.Author) && x.Include(x=>x.BookPublishers) find solution for the inclue more than many entity
var book = await _bookRepository.GetAsync(x=>x.Id == request.Id ,include:x=>
x.Include(x=>x.Category) &&
x.Include(x=>x.Author) &&
x.Include(x=>x.BookPublishers));
var mappedBook = _mapper.Map<BookGetByIdDto>(book);
return mappedBook;
}
4 Replies
Jester
Jester3y ago
its .Include(...).Include(...).Include(...) not .xInclude(...) && x.Include...
D.Mentia
D.Mentia3y ago
Also check out .ThenInclude if necessary, to let you include nested entities
Batuhan
BatuhanOP3y ago
Ty it works now blobthumbsup
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server