/// <summary> /// http://msdn.microsoft.com/library/ms254969.aspx /// http://www.devart.com/dotconnect/salesforce/docs/Metadata-GetSchema.html /// </summary> /// <param name="includeColumns"></param> public override void PopulateTablesFromSchema( bool includeColumns, DbConnection connection, bool disposeConnectionAfterExecute) { ///TODO Look at using SQL MSO (Server Management Objects) http://msdn.microsoft.com/en-us/magazine/cc163409.aspx try { if (connection == null) { connection = new SqlConnection(_connectionString); } if (connection.State != ConnectionState.Open) { connection.Open(); } DataTable schema = connection.GetSchema("Tables"); _tables.Clear(); foreach (DataRow row in schema.Rows) { SqlDatabaseTableGenericWindows <object> table = new SqlDatabaseTableGenericWindows <object>(row, _connectionString); if (table.IsSystemTable) { continue; } if (_tables.Exists(table.TableName)) { throw new Exception(string.Format( "{0} with name {1} already added to {2}.", typeof(SqlDatabaseTableGenericWindows <object>).FullName, table.TableName, this.GetType().FullName)); } ; _tables.Add(table.TableName, table); } if (includeColumns) { _tables.ToList().ForEach(t => t.PopulateColumnsFromSchema(connection, false)); } PopulateChildrenTables(); } finally { if (disposeConnectionAfterExecute && connection != null && connection.State != ConnectionState.Closed) { connection.Dispose(); } } }
public SqlDatabaseTableGenericWindows <E> AddTable <E>(string tableName) where E : class { if (_tables.Exists(tableName)) { throw new Exception(string.Format( "{0} with name {1} already added to {2}.", typeof(SqlDatabaseTableGenericWindows <E>).FullName, tableName, this.GetType().FullName)); } SqlDatabaseTableGenericWindows <E> table = new SqlDatabaseTableGenericWindows <E>(tableName, _connectionString); _tables.Add(table); return(table); }
public SqlDatabaseTableGenericWindows <E> GetSqlDatabaseTable <E>(string tableName) where E : class { if (!_tables.Exists(tableName)) { return(null); } SqlDatabaseTableGenericWindows <E> result = _tables[tableName] as SqlDatabaseTableGenericWindows <E>; if (result == null) { throw new InvalidCastException(string.Format( "Unexpected table type in {0}. Could not type cast {1} to a {2}.", this.GetType().FullName, typeof(DatabaseWindows).FullName, typeof(SqlDatabaseTableGenericWindows <E>).FullName)); } return(result); }
public List <E> Query <E>( string columnName, object columnValue, string propertyNameFilter, bool disposeConnectionAfterExecute, DbConnection connection, DbTransaction transaction) where E : class { SqlDatabaseTableGenericWindows <E> table = GetSqlDatabaseTable <E>(); if (table == null) { throw new NullReferenceException(string.Format( "Could not find {0} with name {1}.", typeof(DatabaseTableWindows).FullName, typeof(E).Name)); } List <object> queryResults = Query(columnName, columnValue, propertyNameFilter, typeof(E), disposeConnectionAfterExecute, connection, transaction); List <E> results = new List <E>(); queryResults.ForEach(p => results.Add((E)p)); return(results); }