public static void SeedBooks(BookShopDbContext context) { var books = GetBooks(); context.Set <Book>().AddRange(books); context.SaveChanges(); }
public Task Insert(Book book, CancellationToken cancellationToken) { _context.Set <Book>().Add(book); return(Task.CompletedTask); }
public GenericRepository(BookShopDbContext db) { this.db = db; table = db.Set <T>(); }
// 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); }
public async Task <Book> GetById(int id) { return(await _context .Set <Book>() .FirstOrDefaultAsync(x => x.BookId == id)); }