Example #1
0
    public async Task <BookDto> GetByIdAsync(long id)
    {
        var sql_ = Db.NewSql();

        sql_.Line("SELECT * FROM Book WHERE Id=@id");
        var book = await Db.FirstOrDefaultAsync <BookDto>(sql_, new { id });

        NotFoundException.ThrowIf(book == null);

        sql_.Clear();
        sql_.Line("SELECT T.*")
        .Line("FROM BookTag BT")
        .Line("LEFT JOIN Tag T ON T.Id=BT.TagId")
        .Line("WHERE BT.BookId=@id");
        book.Tags = (await Db.QueryAsync <Tag>(sql_, new { id })).ToList();

        return(book);
    }