public async Task <T> AddAsync(T entity) { await _dbContext.Set <T>().AddAsync(entity); await _dbContext.SaveChangesAsync(); return(entity); }
private static List <T> CreateItems <T>(BookStoreDbContext db, string filePath) where T : class { var jsonData = File.ReadAllText(filePath); var items = JsonConvert.DeserializeObject <List <T> >(jsonData); db.Set <T>().AddRange(items); return(items); }
protected Repository(BookStoreDbContext db) { Db = db; DbSet = db.Set <TEntity>(); }
public Repository(BookStoreDbContext dbContext) { _dbContext = dbContext ?? throw new ArgumentException(nameof(dbContext)); _table = dbContext.Set <T>(); }
public GenericRepository(BookStoreDbContext dbContext) { _dbContext = dbContext; _dbSet = _dbContext.Set <TEntity>(); }
public async Task <T> GetById(int id) { return(await _dbContext.Set <T>().FindAsync(id)); }
public Repository(BookStoreDbContext db) { Db = db; DbSet = db.Set <T>(); }
public void Add(T entity) { entity.CreateTime = DateTime.UtcNow; entity.UpdatedTime = DateTime.UtcNow; _context.Set <T>().Add(entity); }
public GenericRepository(BookStoreDbContext context) { _context = context; _table = context.Set <T>(); }
public BookRepository(BookStoreDbContext dbContext) { this._dbSet = dbContext.Set <Book>(); }
// GET: Users/Create public IActionResult Create() { ViewData["GenderId"] = new SelectList(_context.Set <Gender>(), "Id", "Name"); ViewData["RoleId"] = new SelectList(_context.Set <Role>(), "Id", "Name"); return(View()); }