Example #1
0
 public static void Init()
 {
     try
     {
         var json = ResourceHelper.GetEmbeddedResource("Infrastructure.DbSettings.json");
         DbSettings               = json.DeserializeJson <DbSettings>();
         _currentDbConnection     = DbSettings.GetCurrentConnection();
         _currentDataProvider     = getDataProviderByDbConnectionType(_currentDbConnection);
         _currentConnectionString = _currentDbConnection.ConnectionString;
         DbType = _currentDbConnection.Type;
     }
     catch (Exception ex)
     {
         throw new DbCriticalException(ex.Message);
     }
     _isInitialized = true;
 }
Example #2
0
        private static LinqToDB.DataProvider.IDataProvider getDataProviderByDbConnectionType(BaseDbConnectionSetting dbConnection)
        {
            var type = dbConnection.GetType();

            if (type == typeof(SQLiteConnectionSetting))
            {
                return(new LinqToDB.DataProvider.SQLite.SQLiteDataProvider(LinqToDB.ProviderName.SQLiteClassic));
            }
            else if (type == typeof(PostgreSQLConnectionSetting))
            {
                return(new LinqToDB.DataProvider.PostgreSQL.PostgreSQLDataProvider());
            }
            else
            {
                throw new Exception($"Неизвестный тип подключения {type}");
            }
        }