Пример #1
0
 /// <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 SQLiteConnection(_connectionString);
         }
         if (connection.State != ConnectionState.Open)
         {
             connection.Open();
         }
         DataTable schema = connection.GetSchema("Tables");
         _tables.Clear();
         foreach (DataRow row in schema.Rows)
         {
             SqliteDatabaseTableGenericWindows <object> table = new SqliteDatabaseTableGenericWindows <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(SqliteDatabaseTableGenericWindows <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();
         }
     }
 }
Пример #2
0
        public SqliteDatabaseTableGenericWindows <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(SqliteDatabaseTableGenericWindows <E>).FullName,
                                        tableName,
                                        this.GetType().FullName));
            }
            SqliteDatabaseTableGenericWindows <E> table = new SqliteDatabaseTableGenericWindows <E>(tableName, _connectionString);

            _tables.Add(table);
            return(table);
        }
Пример #3
0
        public SqliteDatabaseTableGenericWindows <E> GetSqlDatabaseTable <E>(string tableName) where E : class
        {
            if (!_tables.Exists(tableName))
            {
                return(null);
            }
            SqliteDatabaseTableGenericWindows <E> result = _tables[tableName] as SqliteDatabaseTableGenericWindows <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(SqliteDatabaseTableGenericWindows <E>).FullName));
            }
            return(result);
        }
Пример #4
0
        public List <E> Query <E>(
            string columnName,
            object columnValue,
            string propertyNameFilter,
            bool disposeConnectionAfterExecute,
            DbConnection connection,
            DbTransaction transaction) where E : class
        {
            SqliteDatabaseTableGenericWindows <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);
        }