I am writing an Entity Framework Command for selecting only one record (books) from the database. It needs to be shown via api where user should provide id via url. Also, since table is related to other tables (writers, genres), it needs to include relevant records from these tables. Book can have more genres and it stores it in BookGenres table which is then related to Genre table. Also, Book has one Writer from table with the same name. BookDto is an object which returns only relevant data for end-user. Command looks like this:

EfGetBookCommand : IGetBookCommand

```
 private readonly LibraryContext _context;

    public EfGetBookCommand(LibraryContext context)
    {
        _context = context;
    }

    public BookDto Execute(int request)
    {
        //var book = _context.Books.AsQueryable();
        var book = _context.Books.AsQueryable();
        if (book == null)
        {
            throw new Exception();
        }

        var result = book
            .Include(b => b.Writer)
            .ThenInclude(w => w.Name)
            .Include(b => b.BookGenres)
            .ThenInclude(bg => bg.Genre)
            .Where(b => b.Id == request)
            .First();

        return new BookDto
        {
            Id = result.Id,
            Title = result.Title,
            Writer = result.Writer.Name,
            Description = result.Description,
            AvailableCount = result.AvailableCount,
            Count = result.Count,
            BookGenres = result.BookGenres.Select(bg => bg.Genre.Name)
        };

```

When I try this in postman via GET request like this: <http://localhost:55666/api/books/4>, i get 404. I am unable to use find since I am unable to combine it with Include. I will show relevant classes.

I already have similar command for returning all books and it works so I am not able to find what is wrong with this.

BooksController (in API application)

```
    public class BooksController : ControllerBase
{
    private IGetBooksCommand _command;
    private IGetBookCommand _command2;

    public BooksController(IGetBooksCommand command, IGetBookCommand command2)
    {
        _command = command;
        _command2 = command2;
    }
 [HttpGet("{id}")]
    public IActionResult Get(int id)
    {
        try
        {
            var BookDto = _command2.Execute(id);
            return Ok(BookDto);
        }
        catch(Exception e)
        {
            return NotFound();
        }
    }

```

BookDto

```
public class BookDto
{
    public int Id { get; set; }
    public string Title { get; set; }
    public string Writer { get; set; }
    public string Description { get; set; }
    public int AvailableCount { get; set; } 
    public int Count { get; set; }
    public IEnumerable<string> BookGenres { get; set; }
}

```

Book (Domain Class for Entity Framework code first approach)

```
   public class Book : BaseEntity
{
    public string Title { get; set; }
    public int WriterId { get; set; }
    public Writer Writer { get; set; }
    public string Description { get; set; }
    public int AvailableCount { get; set; }
    public int Count { get; set; } reserved or not
    public ICollection<BookGenre> BookGenres { get; set; }
    public ICollection<BookReservation> BookReservations { get; set; }
}

```

BookGenre (DomainClass)

```
public class BookGenre
{
    public int BookId { get; set; }
    public int GenreId { get; set; }
    public Book Book { get; set; }
    public Genre Genre { get; set; }
}

```

Genre (DomainClass)

```
public class Genre : BaseEntity
{
    public string Name { get; set; }
    public ICollection<BookGenre> BookGenres { get; set; }
}

```

Writer(DomainClass)

ICommand

```
    public interface ICommand<TRequest>
{
    void Execute(TRequest request);
}
public interface ICommand<TRequest, TResult>
{
    TResult Execute(TRequest request);
}

```

IGetBookCommand

```
    public interface IGetBookCommand : ICommand<int, BookDto>
{

}

```

I should get an BookDto object returned in json, but I Get an 404 error.