示例#1
0
 public IEnumerable <BookVM> GetAll()
 {
     using (context)
     {
         using (var dbTransaction = context.Database.BeginTransaction())
         {
             try
             {
                 // gets all books record and order from highest to lowest
                 var books = context.Books
                             .Include(x => x.Genre)
                             .Include(x => x.BookAuthors)
                             .ThenInclude(x => x.Author)
                             .ToList()
                             .OrderByDescending(x => x.ID);
                 var booksVm = books.Select(x => toViewModel.Book(x));
                 return(booksVm);
             }
             catch (Exception)
             {
                 throw;
             }
         }
     }
 }
示例#2
0
 public IEnumerable <BookVM> GetAll()
 {
     using (context)
     {
         try
         {
             var books   = context.Books.ToList().OrderByDescending(x => x.ID);
             var booksVm = books.Select(x => toViewModel.Book(x));
             return(booksVm);
         }
         catch (Exception)
         {
             throw;
         }
     }
 }
 public IEnumerable <BookVM> GetAll()
 {
     using (context)
     {
         try
         {
             //SELECT * FROM BOOKS ORDER BY ID DESC
             //LinQ EagerLoading
             var books = context.Books
                         .Include(x => x.Genre)
                         .Include(x => x.BookAuthors)
                         .ThenInclude(x => x.Author)
                         .ToList()
                         .OrderByDescending(x => x.ID);
             var booksVm = books.Select(x => toViewModel.Book(x));
             return(booksVm);
         }
         catch (Exception)
         {
             throw;
         }
     }
 }