刹那的菜鸟

博客园 首页 新随笔 联系 管理

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;
}

 
posted on 2018-05-24 14:40  刹那的菜鸟  阅读(382)  评论(0编辑  收藏  举报