Ejemplo n.º 1
0
        public DbContextOptionsBuilder UseDb(DbContextOptionsBuilder builder, DbConnectionStringSettings connectionStringSettings, DbConnectionProviderSettings connectionProviderSettings)
        {
            MicroStrutLibraryExceptionHelper.IsNull(connectionStringSettings, typeof(SqlServerDbContextOptionsBuilderProvider).FullName, LogLevel.Error, "链接字符串配置为空!");
            MicroStrutLibraryExceptionHelper.IsNull(connectionProviderSettings, typeof(SqlServerDbContextOptionsBuilderProvider).FullName, LogLevel.Error, "链接提供者配置为空!");

            return(builder.UseSqlite(connectionStringSettings.ConnectionString));
        }
        public static DbContextOptionsBuilder UseDb(this DbContextOptionsBuilder builder, DbConnectionConfiguration configuration, string dbName)
        {
            MicroStrutLibraryExceptionHelper.IsNull(configuration, typeof(DbContextOptionsBuilderExtensions).FullName, LogLevel.Error, "配置为空!");
            MicroStrutLibraryExceptionHelper.IsNullOrEmpty(dbName, typeof(DbContextOptionsBuilderExtensions).FullName, LogLevel.Error, "链接数据库为空!");

            DbConnectionStringSettings connectionStringSettings = configuration.ConnectionStrings.SingleOrDefault(s => s.Name == dbName);

            MicroStrutLibraryExceptionHelper.IsNull(connectionStringSettings, typeof(DbContextOptionsBuilderExtensions).FullName, LogLevel.Error, $"链接数据库{dbName}对应的配置节为空!");
            DbConnectionProviderSettings providerSettings = configuration.Providers.SingleOrDefault(s => s.Name == connectionStringSettings.ProviderName);

            MicroStrutLibraryExceptionHelper.IsNull(providerSettings, typeof(DbContextOptionsBuilderExtensions).FullName, LogLevel.Error, $"链接数据库{dbName}对应的提供者配置为空!");

            Type providerType = Type.GetType(providerSettings.Type);
            IDbContextOptionsBuilderProvider provider;

            if (string.IsNullOrEmpty(providerSettings.Parameter))
            {
                provider = (IDbContextOptionsBuilderProvider)Activator.CreateInstance(providerType);
            }
            else
            {
                provider = (IDbContextOptionsBuilderProvider)Activator.CreateInstance(providerType, providerSettings.Parameter);
            }
            return(provider.UseDb(builder, connectionStringSettings, providerSettings));
        }
Ejemplo n.º 3
0
        public DbContextOptionsBuilder UseDb(DbContextOptionsBuilder builder, DbConnectionStringSettings connectionStringSettings, DbConnectionProviderSettings connectionProviderSettings)
        {
            MicroStrutLibraryExceptionHelper.IsNull(connectionStringSettings, typeof(SqlServerDbContextOptionsBuilderProvider).FullName, LogLevel.Error, "链接字符串配置为空!");
            MicroStrutLibraryExceptionHelper.IsNull(connectionProviderSettings, typeof(SqlServerDbContextOptionsBuilderProvider).FullName, LogLevel.Error, "链接提供者配置为空!");

            //SQLServer 2008 R2以以下版本
            builder.UseSqlServer(connectionStringSettings.ConnectionString, optionBuilder => optionBuilder.UseRowNumberForPaging());

            return(builder.UseSqlServer(connectionStringSettings.ConnectionString));
        }