Beispiel #1
0
        private IFrameworkContext CreateContext(ProviderType providerType, IDataStoreScope scope)
        {
            var optionsBuilder        = new DbContextOptionsBuilder <FrameworkContext>();
            IFrameworkContext context = null;

            switch (providerType)
            {
            case ProviderType.Sqlite:
                var sqliteOptions = scope == null?
                                    optionsBuilder.UseSqlite(_connectionString).Options:
                                    optionsBuilder.UseSqlite(scope.AsDbConnection()).Options;

                context = new SqliteDbContext(sqliteOptions);
                break;

            case ProviderType.MySql:
                var mySqlOptions = scope == null?
                                   optionsBuilder.UseMySql(_connectionString).Options:
                                   optionsBuilder.UseMySql(scope.AsDbConnection()).Options;

                context = new MySqlDbContext(mySqlOptions);
                break;

            default:
                throw new NotImplementedException($"No provider exists for '{providerType}'.");
            }

            return(scope != null?
                   context.UseTransaction(scope.AsTransaction()) :
                       context);
        }
Beispiel #2
0
 public void ScopeTo(IDataStoreScope scope)
 {
     Database.UseTransaction(scope.AsTransaction());
 }