public static bool Allows(this TableSelectionSet _tableSelectionSet, string schemaName, string tableName) { if (_tableSelectionSet == null || (_tableSelectionSet.Schemas.Count == 0 && _tableSelectionSet.Tables.Count == 0)) { return(true); } var result = false; foreach (var schemaSelection in _tableSelectionSet.Schemas) { if (EqualsWithQuotes(schemaSelection.Text, schemaName)) { schemaSelection.IsMatched = true; result = true; } } foreach (var tableSelection in _tableSelectionSet.Tables) { var components = tableSelection.Text.Split('.'); if (components.Length == 1 ? EqualsWithQuotes(components[0], tableName) : EqualsWithQuotes(components[0], schemaName) && EqualsWithQuotes(components[1], tableName)) { tableSelection.IsMatched = true; result = true; } } return(result); }
/// <summary> /// Creates a new instance of <see cref="DatabaseModel"/> by the specified <paramref name="connection"/> and <paramref name="tableSelectionSet"/>. /// </summary> /// <param name="connection">The db connection.</param> /// <param name="tableSelectionSet">The table selection set.</param> /// <returns>The instance of <see cref="DatabaseModel"/></returns> public DatabaseModel Create(DbConnection connection, TableSelectionSet tableSelectionSet) { ResetState(); _tableSelectionSet = tableSelectionSet; _connection = connection; var connectionStartedOpen = _connection.State == ConnectionState.Open; if (!connectionStartedOpen) { _connection.Open(); } try { _databaseModel.Name = _connection.Database; _databaseModel.Schema = null; GetTables(); GetColumns(); return(_databaseModel); } finally { if (!connectionStartedOpen) { _connection.Close(); } } }