public List<Book> GetBookList()
{
List<Book> bList = null;
try
{
using (var t = new SqlConnection(ConfigurationManager.ConnectionStrings["Test"].ConnectionString))
{
bList= t.Query<Book, BookComment, BookPic, Book>(@"select
a.ID,a.Name,a.Description,
b.Name,b.ID,b.BookId,b.Comment,
c.BookID,c.ID,c.Name,c.PicDesc
from [dbo].[Book]
a inner join [dbo].[BookComment] b on a.id=b.bookid
inner join [dbo].[BookPic] c on a.id =c.bookid",
(book, bookcomment, bookpic) =>
{
book.bookComment = bookcomment;
book.bookPic = bookpic;
return book;
},
splitOn: "Name,BookID"
).ToList();
}
}
catch (Exception ex)
{
nlog.Error(ex.ToString());
}
return bList;
}