コード例 #1
0
        public override IDictionary <string, EntityMap> GetTables()
        {
            Dictionary <string, EntityMap> tables = new Dictionary <string, EntityMap>();

            try
            {
                using (DbDataReader reader = db.ExecuteReader(Connection, SELECT_TABLE_FROM_SCHEMA))
                {
                    int countOrder = 0;
                    while (reader.Read())
                    {
                        string name = reader.GetValueAsString("tbl_name");
                        countOrder++;

                        if (IsTableInFilterList(Dialect.DefaultSchemaName, name))
                        {
                            continue;
                        }

                        EntityMap table = new EntityMap(name, name);
                        table.Namespace    = ProjectSettings.Namespace;
                        table.SchemaName   = Dialect.DefaultSchemaName;
                        table.AssemblyName = ProjectSettings.AssemblyName;
                        table.TableAlias   = name;
                        table.Order        = countOrder;
                        tables.Add(name, table);
                    }
                }

                foreach (var table in tables.Values)
                {
                    var columns = ProcessColumns(table);
                    ProcessReferences(table, columns);
                    ProcessIndex(table, columns);
                    table.AddColumnRange(columns.Values);
                }
            }
            catch (Exception ex)
            {
                Console.Write(ex.ToString());
            }

            return(tables);
        }
コード例 #2
0
        /// <summary>
        /// Gets the tables.
        /// </summary>
        /// <returns></returns>
        public override IDictionary <string, EntityMap> GetTables()
        {
            var tables = new Dictionary <string, EntityMap>();

            try
            {
                using (DbDataReader reader = db.ExecuteReader(Connection, SelectTableFromSchema))
                {
                    int counterOrder = 0;
                    while (reader.Read())
                    {
                        string name       = reader.GetValueAsString("TABLE_NAME");
                        string schemaName = reader.GetValueAsString("TABLE_SCHEMA");

                        counterOrder++;
                        if (FilterSettings.Exclude)
                        {
                            if (IsTableInFilterList(schemaName, name))
                            {
                                continue;
                            }
                        }
                        else
                        {
                            if (!IsTableInFilterList(schemaName, name))
                            {
                                continue;
                            }
                        }

                        if (!string.IsNullOrWhiteSpace(name) && name.Equals("sysdiagrams", StringComparison.OrdinalIgnoreCase))
                        {
                            continue;
                        }


                        string tableId = reader.GetValueAsString("TableId");

                        logger.Log(LogLevel.Info, $"reading table {schemaName}.{name}");
                        string @namespace = ProjectSettings.Namespace;

                        if (!string.IsNullOrWhiteSpace(schemaName) && !Dialect.DefaultSchemaName.ToUpper().Equals(schemaName.ToUpper()))
                        {
                            @namespace = $"{ProjectSettings.Namespace}.{schemaName.ToClrValPascal()}";
                        }

                        var table = new EntityMap(name, name)
                        {
                            Namespace    = @namespace,
                            SchemaName   = schemaName,
                            AssemblyName = ProjectSettings.AssemblyName,
                            TableAlias   = name,
                            Order        = counterOrder,
                            Id           = tableId
                        };

                        tables.Add($"{schemaName}.{name}", table);
                    }
                }
                var tableMetaDataDictionary = GetTableMetaData();

                foreach (var table in tables.Values)
                {
                    logger.Log(LogLevel.Info, $"processing table {table.Name}");
                    var columns = ProcessColumns(table);
                    ProcessConstraints(table, columns);
                    ProcessForeignKeys(table);
                    ProcessReferences(table, columns);
                    table.AddColumnRange(columns.Values);

                    TableMetaData meta;
                    if (tableMetaDataDictionary.TryGetValue(table.Id, out meta))
                    {
                        if (!string.IsNullOrWhiteSpace(meta.Description))
                        {
                            table.MetaDataAttributes.Add("display_description", meta.Description);
                        }

                        foreach (var column in columns)
                        {
                            string colMeta;
                            if (meta.ColumnMetadata.TryGetValue(column.Value.ColumnName, out colMeta))
                            {
                                column.Value.MetaDataAttributes.Add("display_description", colMeta);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error("Error while getting table structure", ex);
                throw;
            }
            return(tables);
        }