Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

label:question Does this work for lists? Such as (1) book might have (n) Authors? #24

Open
jeffward01 opened this issue Apr 13, 2021 · 1 comment
Labels
question Further information is requested

Comments

@jeffward01
Copy link

jeffward01 commented Apr 13, 2021

Basically I have many lists where I need to return ALL authors who wrote Book XYZ.

For example, if Book XYZ has (3) Authors, when I query Book XZY, I need all (3) child authors in the collection to be returned.

From looking at the code, I do not think this feature is included. I wanted to ask to confirm if its included or not. Thanks

label:question

@gdlcf88 gdlcf88 added the question Further information is requested label Apr 14, 2021
@gdlcf88
Copy link
Member

gdlcf88 commented Apr 14, 2021

Try this:

public class Book : AggregateRoot<Guid>
{
    public virtual List<BookAuthor> BookAuthors { get; protected set; }

    // ctor
}

public class BookAuthor : Entity<Guid>
{
    public virtual Guid BookId { get; protected set; }

    public virtual Guid AuthorId { get; protected set; }

    // ctor
}
public class BookDto : EntityDto<Guid>
{
    public List<BookAuthorDto> BookAuthors { get; set; }
}

public class BookAuthorDto : EntityDto<Guid>
{
    public Guid BookId { get; set; }

    [RelatedDto]
    public AuthorDto Author { get; set; }
}
var bookDto = ObjectMapper.Map<Book, BookDto>(await _bookRepository.GetAsync(id));

return await _relatedDtoLoader.LoadListAsync(bookDto.BookAuthors); 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants