示例#1
0
        public async Task CopyDatas(BonusDbContext from, BonusDbContext to)
        {
            var dbSets = GetAllDbSets();

            var allDbSets = dbSets.Select(dbSet => dbSet.GetValue(from)).OfType <IQueryable <object> >();

            foreach (var dbSet in allDbSets)
            {
                to.AddRange(await dbSet.ToListAsync());
            }
            await to.SaveChangesAsync();
        }
示例#2
0
        private async Task <BonusDbContext> GetDbContext()
        {
            var connection = new SqliteConnection("Filename=:memory:");

            connection.Open();

            var options = new DbContextOptionsBuilder <BonusDbContext>()
                          .UseSqlite(connection)
                          .Options;
            var dbContext = new BonusDbContext(options);
            await dbContext.Database.MigrateAsync();

            return(dbContext);
        }
示例#3
0
 private async Task AddData(BonusDbContext dbContext)
 {
     dbContext.GuildsSettings.Add(new GuildsSettings {
         GuildId = 0, Key = "Key", Module = "Module", Value = "Value"
     });
     dbContext.Logs.AddRange(new Logs {
         Id = 1
     }, new Logs {
         Id = 2
     }, new Logs {
         Id = 3
     });
     dbContext.TimedActions.Add(new TimedActions {
         Id = 5
     });
     await dbContext.SaveChangesAsync();
 }