public static void SeedBooks(BookShopDbContext context)
        {
            var books = GetBooks();

            context.Set <Book>().AddRange(books);

            context.SaveChanges();
        }
예제 #2
0
 public Task Insert(Book book, CancellationToken cancellationToken)
 {
     _context.Set <Book>().Add(book);
     return(Task.CompletedTask);
 }
예제 #3
0
 public GenericRepository(BookShopDbContext db)
 {
     this.db = db;
     table   = db.Set <T>();
 }
예제 #4
0
 // Phương thức khởi tạo
 public GenericRepository()
 {
     db    = new BookShopDbContext();
     table = db.Set <T>();
 }
 public static void Reinitialize(BookShopDbContext context)
 {
     context.Set <Book>().RemoveRange(GetBooks());
     context.SaveChanges();
     Initialize(context);
 }
예제 #6
0
 public async Task <Book> GetById(int id)
 {
     return(await _context
            .Set <Book>()
            .FirstOrDefaultAsync(x => x.BookId == id));
 }