Example #1
0
    public async Task CanCreateUserIntViaSet()
    {
        using (var db = new CustomDbContext <int>(
                   new DbContextOptionsBuilder().UseSqlite($"DataSource=D{Guid.NewGuid()}.db").Options))
        {
            db.Database.EnsureCreated();

            var user  = new User <int>();
            var users = db.Set <User <int> >();
            users.Add(user);
            await db.SaveChangesAsync();

            user.UserName = "******";
            await db.SaveChangesAsync();

            var fetch = users.First(u => u.UserName == "Boo");
            Assert.Equal(user, fetch);

            db.Database.EnsureDeleted();
        }
    }
Example #2
0
 /// <summary>
 /// Constructor for pass db context
 /// </summary>
 /// <param name="db"></param>
 public GenericRepository(CustomDbContext db)
 {
     this.db = db;
     table   = db.Set <T>();
 }
Example #3
0
 /// <summary>
 /// Constructor
 /// </summary>
 public GenericRepository()
 {
     this.db = new CustomDbContext();
     table   = db.Set <T>();
 }
 public GenericRepository(CustomDbContext context)
 {
     dbContext = context;
     entities  = context.Set <TEntity>();
 }
Example #5
0
 public IQueryable <T> GetAll()
 {
     return(_context.Set <T>().AsNoTracking());
 }
Example #6
0
 public BaseController(CustomDbContext context)
 {
     _context = context;
     _dbSet   = context?.Set <T>();
 }