Beispiel #1
0
 /// <summary>
 /// Setups the columns.
 /// </summary>
 /// <param name="table">The table.</param>
 /// <param name="item">The item.</param>
 private static void SetupColumns(ITable table, dynamic item)
 {
     if (item is null)
     {
         throw new ArgumentNullException(nameof(item));
     }
     if (table is null)
     {
         throw new ArgumentNullException(nameof(table));
     }
     if (table.ContainsColumn(item.Column))
     {
         table.AddForeignKey(item.Column, item.FOREIGN_KEY_TABLE, item.FOREIGN_KEY_COLUMN);
     }
     else
     {
         string ColumnType = item.COLUMN_TYPE;
         table.AddColumn <string>(item.Column,
                                  ColumnType.To <SqlDbType>().To <DbType>(),
                                  (item.COLUMN_TYPE == "nvarchar") ? item.MAX_LENGTH / 2 : item.MAX_LENGTH,
                                  item.IS_NULLABLE,
                                  item.IS_IDENTITY,
                                  !(item.IS_INDEX is null),
                                  !string.IsNullOrEmpty(item.PRIMARY_KEY),
                                  !string.IsNullOrEmpty(item.UNIQUE),
                                  item.FOREIGN_KEY_TABLE,
                                  item.FOREIGN_KEY_COLUMN,
                                  item.DEFAULT_VALUE,
                                  item.ComputedColumnSpecification);
     }
 }
Beispiel #2
0
 /// <summary>
 /// Setups the columns.
 /// </summary>
 /// <param name="table">The table.</param>
 /// <param name="item">The item.</param>
 private static void SetupColumns(ITable table, dynamic item)
 {
     if (item == null)
     {
         throw new ArgumentNullException(nameof(item));
     }
     if (table == null)
     {
         throw new ArgumentNullException(nameof(table));
     }
     if (table.ContainsColumn(item.Column))
     {
         table.AddForeignKey(item.Column, item.FOREIGN_KEY_TABLE, item.FOREIGN_KEY_COLUMN);
     }
     else
     {
         table.AddColumn <string>(item.Column,
                                  Utilities.DataTypes.TypeConversionExtensions.To(Utilities.DataTypes.TypeConversionExtensions.To <string, SqlDbType>(item.COLUMN_TYPE), DbType.Int32),
                                  (item.COLUMN_TYPE == "nvarchar") ? item.MAX_LENGTH / 2 : item.MAX_LENGTH,
                                  item.IS_NULLABLE,
                                  item.IS_IDENTITY,
                                  item.IS_INDEX != 0,
                                  !string.IsNullOrEmpty(item.PRIMARY_KEY),
                                  !string.IsNullOrEmpty(item.UNIQUE),
                                  item.FOREIGN_KEY_TABLE,
                                  item.FOREIGN_KEY_COLUMN,
                                  item.DEFAULT_VALUE);
     }
 }
Beispiel #3
0
        internal static void BuildLargeSampleData(ITable table)
        {
            const int limit = 100000;
            var       seed  = Enumerable.Range(0, limit);

            // Define desired columns
            table.AddColumn(new ColumnDetails("ID", "int", -1, "i", true));
            table.AddColumn(new ColumnDetails("AllOnes", "int", 1, "ao", false));
            table.AddColumn(new ColumnDetails("AllEvens", "short", 0, "even", false));

            DataBlock items = new DataBlock(new string[] { "ID", "AllOnes", "AllEvens" }, limit);

            items.SetColumn(0, seed.ToArray());
            items.SetColumn(1, seed.Select(i => 1).ToArray());
            items.SetColumn(2, seed.Select(i => i % 2).ToArray());

            table.AddOrUpdate(items, new AddOrUpdateOptions());
        }
Beispiel #4
0
        private void ITable_ColumnManagement(Func <ITable> factoryMethod)
        {
            ITable table = factoryMethod();

            AddSampleData(table);

            // Add a new column with a non-null default
            string newColumnName           = "Area Path";
            string newColumnInitialDefault = "5";

            table.AddColumn(new ColumnDetails(newColumnName, "string", newColumnInitialDefault));

            // Verify all rows have the new default
            SelectQuery  query  = new SelectQuery(new string[] { "ID", newColumnName }, "");
            SelectResult result = table.Query(query);

            Assert.AreEqual(5, (int)result.Total);
            for (int i = 0; i < result.Values.RowCount; ++i)
            {
                Assert.AreEqual(newColumnInitialDefault, result.Values[i, 1].ToString());
            }

            // Change the column type (string to ushort)
            ushort newColumnSecondDefault = 10;

            table.AlterColumn(new ColumnDetails(newColumnName, "ushort", newColumnSecondDefault));

            // Verify existing values have been re-typed
            result = table.Query(query);
            Assert.AreEqual(5, (int)result.Total);
            for (int i = 0; i < result.Values.RowCount; ++i)
            {
                Assert.AreEqual((ushort)5, result.Values[i, 1]);
            }

            // Verify column knows the new default
            DataBlock items = new DataBlock(new string[] { "ID" }, 1);

            items[0, 0] = 12345;
            table.AddOrUpdate(items, new AddOrUpdateOptions());

            query  = new SelectQuery(query.Columns, "ID = 12345");
            result = table.Query(query);
            Assert.AreEqual(1, (int)result.Total);
            Assert.AreEqual(newColumnSecondDefault, result.Values[0, 1]);

            // Delete the column
            table.RemoveColumn(newColumnName);

            foreach (ColumnDetails cd in table.ColumnDetails)
            {
                if (cd.Name.Equals(newColumnName))
                {
                    Assert.Fail("Column not removed after RemoveColumn() called.");
                }
            }
        }
Beispiel #5
0
        private static IColumn CloneColumn(ITable primaryTable, ITable foreignTable, IColumn column, string columnNamePrefix)
        {
            var newColumn = column.Clone();
            var name      = columnNamePrefix + primaryTable.Name + "_" + column.Name;

            newColumn.Name = name.GetNextName(foreignTable.Columns.Select(c => c.Name));

            foreignTable.AddColumn(newColumn);

            return(newColumn);
        }
Beispiel #6
0
        internal static void AddColumns(ITable table)
        {
            // Define desired columns
            table.AddColumn(new ColumnDetails("ID", "int", -1, "i", true));
            table.AddColumn(new ColumnDetails("Title", "string", null, "t", false));
            table.AddColumn(new ColumnDetails("Priority", "short", -1, "p", false));
            table.AddColumn(new ColumnDetails("Created Date", "DateTime", DateTime.MinValue.ToUniversalTime(), "cd", false));
            table.AddColumn(new ColumnDetails("Primary Bug ID", "int", -1, "pID", false));

            table.AddColumn(new ColumnDetails("IsDuplicate", "bool", true, "", false));
            table.AddColumn(new ColumnDetails("ActiveTime", "TimeSpan", null, "at", false));
        }
 private static void SetupProperties(ITable Table, IMapping Mapping)
 {
     Contract.Requires <ArgumentNullException>(Mapping != null, "Mapping");
     Contract.Requires <ArgumentNullException>(Table != null, "Table");
     Contract.Requires <ArgumentNullException>(Mapping.IDProperties != null, "Mapping.IDProperties");
     Mapping.IDProperties
     .ForEach(x =>
     {
         Table.AddColumn(x.FieldName,
                         x.Type.To(DbType.Int32),
                         x.MaxLength,
                         x.NotNull,
                         x.AutoIncrement,
                         x.Index,
                         true,
                         x.Unique,
                         "",
                         "",
                         "");
     });
     Mapping.Properties
     .Where(x => !(x is IMultiMapping || x is ISingleMapping || x is IMap))
     .ForEach(x =>
     {
         Table.AddColumn(x.FieldName,
                         x.Type.To(DbType.Int32),
                         x.MaxLength,
                         !x.NotNull,
                         x.AutoIncrement,
                         x.Index,
                         false,
                         x.Unique,
                         "",
                         "",
                         "");
     });
 }
        public void GenerateSchema()
        {
            var     Temp   = new Utilities.ORM.Manager.Schema.Default.Database.SQLServer.SQLServerSchemaGenerator(Utilities.IoC.Manager.Bootstrapper.Resolve <Utilities.ORM.Manager.QueryProvider.Manager>(), Utilities.IoC.Manager.Bootstrapper.Resolve <Utilities.ORM.Manager.SourceProvider.Manager>());
            ISource Source = Temp.GetSourceStructure(TestDatabaseSource);

            Source.Tables.First().AddColumn <string>("A", DbType.Int16);
            ITable Table = Source.AddTable("TestTable2");

            Table.AddColumn <string>("A", DbType.Int16);
            IEnumerable <string> Commands = Temp.GenerateSchema(Source, TestDatabaseSource);

            Assert.Equal(2, Commands.Count());
            Assert.Equal("EXEC dbo.sp_executesql @statement = N'ALTER TABLE TestTable ADD A SmallInt'", Commands.First());
            Assert.Equal("EXEC dbo.sp_executesql @statement = N'CREATE TABLE TestTable2(A SmallInt)'", Commands.Last());
        }
        protected override void RunOperationInternal()
        {
            IColumn col = Object.Clone();

            Table.AddColumn(col);

            // Add new column to mapped entities
            foreach (var entity in Table.MappedEntities())
            {
                ArchAngel.Interfaces.ProjectOptions.ModelScripts.Scripts.ExistingPropertyNames = entity.Properties.Select(p => p.Name).ToList();
                ArchAngel.Providers.EntityModel.Model.EntityLayer.Property newProperty = ArchAngel.Providers.EntityModel.Controller.MappingLayer.OneToOneEntityProcessor.CreatePropertyFromColumn(col);
                entity.AddProperty(newProperty);
                newProperty.SetMappedColumn(col);
            }
        }
Beispiel #10
0
 /// <summary>
 /// Adds to table.
 /// </summary>
 /// <param name="table">The table.</param>
 public void AddToTable(ITable table)
 {
     table?.AddColumn(ColumnName,
                      PropertyType.To(DbType.Int32),
                      MaxLength,
                      Nullable,
                      AutoIncrement,
                      Index,
                      true,
                      false,
                      "",
                      "",
                      DefaultValue(),
                      ComputedColumnSpecification);
 }
Beispiel #11
0
        private void GetColumns(ITable table)
        {
            Type   uniDBType      = typeof(SQLServer.UniDbTypes);
            string cleanTableName = table.Name.Replace("'", "''");

            if (!connector.ColumnsBySchema.ContainsKey(table.Schema))
            {
                return;
            }

            if (!connector.ColumnsBySchema[table.Schema].ContainsKey(cleanTableName))
            {
                return;
            }

            List <DataRow> columnRows = connector.ColumnsBySchema[table.Schema][cleanTableName];

            foreach (DataRow columnRow in columnRows)
            {
                bool isReadOnly = false;

                if (Slyce.Common.Utility.StringsAreEqual((string)columnRow["DATA_TYPE"], "timestamp", false))
                {
                    isReadOnly = true;
                }
                Column column = new Column();
                column.Name             = (string)columnRow["COLUMN_NAME"];
                column.IsUserDefined    = false;
                column.Parent           = table;
                column.IsIdentity       = columnRow["IsIdentity"] is DBNull ? false : (Convert.ToInt32(columnRow["IsIdentity"])) == 1;
                column.OrdinalPosition  = Convert.ToInt32(columnRow["ORDINAL_POSITION"]);
                column.IsNullable       = ((string)columnRow["IS_NULLABLE"]).StartsWith("Y", StringComparison.InvariantCultureIgnoreCase);
                column.Precision        = columnRow.IsNull("NUMERIC_PRECISION") ? 0 : Convert.ToInt32(columnRow["NUMERIC_PRECISION"]);
                column.Scale            = columnRow.IsNull("NUMERIC_SCALE") ? 0 : Convert.ToInt32(columnRow["NUMERIC_SCALE"]);
                column.OriginalDataType = (string)columnRow["DATA_TYPE"];
                column.Size             = columnRow.IsNull("CHARACTER_MAXIMUM_LENGTH")     //|| column.Datatype == "ntext" || column.Datatype == "text" // ntext/text returns useless length
                                                                ? 0
                                                                : Convert.ToInt64(columnRow["CHARACTER_MAXIMUM_LENGTH"]);
                column.InPrimaryKey = connector.DoesColumnHaveConstraint(column, "PRIMARY KEY");
                column.IsUnique     = connector.DoesColumnHaveConstraint(column, "UNIQUE");
                column.Default      = columnRow.IsNull("COLUMN_DEFAULT") ? "" : (string)columnRow["COLUMN_DEFAULT"];
                column.IsReadOnly   = isReadOnly;

                column.ResetDefaults();

                table.AddColumn(column);
            }
        }
Beispiel #12
0
        private static void SetupDatabase(IDatabase db, int numTables, int numColumns)
        {
            for (int i = 0; i < numTables; i++)
            {
                db.AddTable(new Table("Table" + i, ""));
            }

            for (int i = 0; i < db.Tables.Count; i++)
            {
                ITable table = db.Tables[i];
                for (int j = 0; j < numColumns; j++)
                {
                    table.AddColumn(new Column("Column" + j));
                }
            }
        }
        public void Setup()
        {
            set = new MappingSetImpl();
            entity = new EntityImpl("Entity1");
            set.EntitySet.AddEntity(entity);
            table = new Table("Table1");
            table.AddColumn(new Column("Street"));
            set.Database.AddTable(table);

            spec = new ComponentSpecificationImpl("Address");
            spec.AddProperty(new ComponentPropertyImpl("Street"));
            set.EntitySet.AddComponentSpecification(spec);

            component = spec.CreateImplementedComponentFor(entity, "HomeAddress");
            set.ChangeMappingFor(component.Properties[0]).To(table.Columns[0]);
        }
        public void Setup()
        {
            set    = new MappingSetImpl();
            entity = new EntityImpl("Entity1");
            set.EntitySet.AddEntity(entity);
            table = new Table("Table1");
            table.AddColumn(new Column("Street"));
            set.Database.AddTable(table);

            spec = new ComponentSpecificationImpl("Address");
            spec.AddProperty(new ComponentPropertyImpl("Street"));
            set.EntitySet.AddComponentSpecification(spec);

            component = spec.CreateImplementedComponentFor(entity, "HomeAddress");
            set.ChangeMappingFor(component.Properties[0]).To(table.Columns[0]);
        }
Beispiel #15
0
 /// <summary>
 /// Adds to a child table.
 /// </summary>
 /// <param name="table">The table.</param>
 public void AddToChildTable(ITable table)
 {
     table?.AddColumn(ParentMapping.TableName + ColumnName,
                      PropertyType.To(DbType.Int32),
                      MaxLength,
                      Nullable,
                      false,
                      Index,
                      false,
                      true,
                      ParentMapping.TableName,
                      ColumnName,
                      DefaultValue(),
                      ComputedColumnSpecification,
                      true,
                      true);
 }
Beispiel #16
0
 /// <summary>
 /// Adds to child table.
 /// </summary>
 /// <param name="table">The table.</param>
 public void AddToChildTable(ITable table)
 {
     table.AddColumn <long>(ParentMapping.TableName + ColumnName,
                            System.Data.DbType.Int64,
                            0,
                            false,
                            false,
                            false,
                            false,
                            true,
                            ParentMapping.TableName,
                            ColumnName,
                            0,
                            "",
                            true,
                            true);
 }
 /// <summary>
 /// Adds to table.
 /// </summary>
 /// <param name="table">The table.</param>
 public void AddToTable(ITable table)
 {
     ForeignMapping.ForEach(TempMapping => TempMapping.IDProperties.ForEach(x =>
     {
         table.AddColumn <object>(TempMapping.TableName + ParentMapping.Prefix + Name + ParentMapping.Suffix + x.ColumnName,
                                  x.PropertyType.To(DbType.Int32),
                                  x.MaxLength,
                                  true,
                                  false,
                                  false,
                                  false,
                                  Unique,
                                  TempMapping.TableName,
                                  x.ColumnName,
                                  null !,
                                  "",
                                  false,
                                  false,
                                  SetNullOnDelete);
     }));
 }
        /// <summary>
        /// Setups the stored procedures.
        /// </summary>
        /// <param name="storedProcedure">The stored procedure.</param>
        /// <param name="item">The item.</param>
        private static void SetupStoredProcedures(ITable storedProcedure, dynamic item)
        {
            if (storedProcedure is null)
            {
                throw new ArgumentNullException(nameof(storedProcedure));
            }
            if (item is null)
            {
                throw new ArgumentNullException(nameof(item));
            }
            string Type   = item.TYPE;
            string Name   = item.NAME;
            int    Length = item.LENGTH;

            if (Type == "nvarchar")
            {
                Length /= 2;
            }
            string Default = item.DEFAULT_VALUE;

            storedProcedure.AddColumn <string>(Name, Type.To <SqlDbType>().To <DbType>(), Length, defaultValue: Default);
        }
        private void GetColumns(ITable table)
        {
            Type uniDBType = typeof(SQLServer.UniDbTypes);

            DataRow[] columnRows = connector.Columns.Select(string.Format("TABLE_NAME = '{0}' AND TABLE_SCHEMA = '{1}'", table.Name.Replace("'", "''"), table.Schema));

            foreach (DataRow columnRow in columnRows)
            {
                bool isReadOnly = false;

                if (Slyce.Common.Utility.StringsAreEqual(((string)columnRow["DATA_TYPE"]), "timestamp", false))
                {
                    isReadOnly = true;
                }
                Column column = new Column();
                column.Name             = ((string)columnRow["COLUMN_NAME"]);
                column.IsUserDefined    = false;
                column.Parent           = table;
                column.IsIdentity       = columnRow["IsIdentity"] is DBNull ? false : ((int)columnRow["IsIdentity"]) == 1;
                column.OrdinalPosition  = (short)columnRow["ORDINAL_POSITION"];
                column.IsNullable       = (int)columnRow["IS_NULLABLE"] > 0;
                column.OriginalDataType = (string)columnRow["DATA_TYPE"];
                column.Size             = columnRow.IsNull("CHARACTER_MAXIMUM_LENGTH") /*|| column.OriginalDataType.ToLowerInvariant() == "nclob" || column.OriginalDataType.ToLowerInvariant() == "text"*/     // ntext/text returns useless length
                                                                ? 0
                                                                : Convert.ToInt64(columnRow["CHARACTER_MAXIMUM_LENGTH"]);
                column.InPrimaryKey = connector.DoesColumnHaveConstraint(column, "PRIMARY KEY");
                column.IsUnique     = connector.DoesColumnHaveConstraint(column, "UNIQUE");
                column.Default      = columnRow.IsNull("COLUMN_DEFAULT") ? "" : ((string)columnRow["COLUMN_DEFAULT"]);
                column.IsReadOnly   = isReadOnly;
                column.Precision    = columnRow.IsNull("NUMERIC_PRECISION") ? 0 : Convert.ToInt32(columnRow["NUMERIC_PRECISION"]);
                column.Scale        = columnRow.IsNull("NUMERIC_SCALE") ? 0 : Convert.ToInt32(columnRow["NUMERIC_SCALE"]);

                column.ResetDefaults();

                table.AddColumn(column);
            }
        }
Beispiel #20
0
        private void GetColumns(ITable table)
        {
            Type uniDBType = typeof(SQLServer.UniDbTypes);

            DataRow[] columnRows = connector.Columns.Select(string.Format("TABLE_NAME = '{0}'", table.Name.Replace("'", "''")));

            foreach (DataRow columnRow in columnRows)
            {
                bool isReadOnly = false;

                if (Slyce.Common.Utility.StringsAreEqual((string)columnRow["DATA_TYPE"], "timestamp", false))
                {
                    isReadOnly = true;
                }
                Column column = new Column();
                column.Name             = (string)columnRow["COLUMN_NAME"];
                column.IsUserDefined    = false;
                column.Parent           = table;
                column.IsIdentity       = "TRUE".Equals((string)columnRow["IS_IDENTITY"], StringComparison.OrdinalIgnoreCase);
                column.OrdinalPosition  = (int)columnRow["ORDINAL_POSITION"];
                column.IsNullable       = Slyce.Common.Utility.StringsAreEqual((string)columnRow["IS_NULLABLE"], "YES", false);
                column.OriginalDataType = (string)columnRow["DATA_TYPE"];
                column.Size             = columnRow.IsNull("CHARACTER_MAXIMUM_LENGTH")
                                                                ? 0
                                                                : Convert.ToInt64(columnRow["CHARACTER_MAXIMUM_LENGTH"]);
                column.InPrimaryKey = connector.DoesColumnHaveConstraint(column, "PRIMARY KEY");
                column.IsUnique     = connector.DoesColumnHaveConstraint(column, "UNIQUE");
                column.Default      = columnRow.IsNull("COLUMN_DEFAULT") ? "" : (string)columnRow["COLUMN_DEFAULT"];
                column.IsReadOnly   = isReadOnly;
                column.Precision    = columnRow.IsNull("NUMERIC_PRECISION") ? 0 : Convert.ToInt32(columnRow["NUMERIC_PRECISION"]);
                column.Scale        = columnRow.IsNull("NUMERIC_SCALE") ? 0 : Convert.ToInt32(columnRow["NUMERIC_SCALE"]);

                column.ResetDefaults();

                table.AddColumn(column);
            }
        }
Beispiel #21
0
        public void Setup()
        {
            EntitySet entitySet = new EntitySetImpl();

            entity = new EntityImpl("Entity1");
            entity.AddProperty(new PropertyImpl {
                Name = "Property1"
            });
            entitySet.AddEntity(entity);

            IDatabase database = new Database("DB1");

            table = new Table("Table");
            table.AddColumn(new Column("Column1"));
            database.AddEntity(table);

            Mapping mapping = new MappingImpl();

            mapping.AddPropertyAndColumn(entity.Properties.ElementAt(0), table.Columns[0]);

            MappingSet mappingSet = new MappingSetImpl(database, entitySet);

            mappingSet.AddMapping(mapping);
        }
Beispiel #22
0
 protected int AddColumn <T>(string cname)
 {
     return(_table.GetColumnIndex(_table.AddColumn <T>(cname)));
 }
        private void GetColumns(ITable table)
        {
            Type uniDBType = typeof(SQLServer.UniDbTypes);

            DataRow[] columnRows = connector.Columns.Select(string.Format("TABLE_NAME = '{0}' AND TABLE_SCHEMA = '{1}'", table.Name.Replace("'", "''"), table.Schema));

            foreach (DataRow columnRow in columnRows)
            {
                bool isReadOnly = false;

                if (Slyce.Common.Utility.StringsAreEqual((string)columnRow["DATA_TYPE"], "timestamp", false))
                {
                    isReadOnly = true;
                }
                Column column = new Column();
                column.Name = (string)columnRow["COLUMN_NAME"];
                column.IsUserDefined = false;
                column.Parent = table;
                column.IsIdentity = columnRow["IsIdentity"] is DBNull ? false : (Convert.ToInt32(columnRow["IsIdentity"])) == 1;
                column.OrdinalPosition = Convert.ToInt32(columnRow["ORDINAL_POSITION"]);
                column.IsNullable = Slyce.Common.Utility.StringsAreEqual((string)columnRow["IS_NULLABLE"], "YES", false);
                column.OriginalDataType = (string)columnRow["DATA_TYPE"];
                column.Size = columnRow.IsNull("CHARACTER_MAXIMUM_LENGTH") //|| column.Datatype == "ntext" || column.Datatype == "text" // ntext/text returns useless length
                                ? 0
                                : Convert.ToInt64(columnRow["CHARACTER_MAXIMUM_LENGTH"]);
                column.InPrimaryKey = connector.DoesColumnHaveConstraint(column, "PRIMARY KEY");
                column.IsUnique = connector.DoesColumnHaveConstraint(column, "UNIQUE");
                column.Default = columnRow.IsNull("COLUMN_DEFAULT") ? "" : (string)columnRow["COLUMN_DEFAULT"];
                column.IsReadOnly = isReadOnly;
                column.Precision = columnRow.IsNull("NUMERIC_PRECISION") ? 0 : Convert.ToInt32(columnRow["NUMERIC_PRECISION"]);
                column.Scale = columnRow.IsNull("NUMERIC_SCALE") ? 0 : Convert.ToInt32(columnRow["NUMERIC_SCALE"]);

                column.ResetDefaults();

                table.AddColumn(column);
            }
        }
 private static void SetupProperties(ITable Table, IMapping Mapping)
 {
     Contract.Requires<ArgumentNullException>(Mapping != null, "Mapping");
     Contract.Requires<ArgumentNullException>(Table != null, "Table");
     Contract.Requires<ArgumentNullException>(Mapping.IDProperties != null, "Mapping.IDProperties");
     Mapping.IDProperties
            .ForEach(x =>
     {
         Table.AddColumn(x.FieldName,
             x.Type.To(DbType.Int32),
             x.MaxLength,
             x.NotNull,
             x.AutoIncrement,
             x.Index,
             true,
             x.Unique,
             "",
             "",
             "");
     });
     Mapping.Properties
            .Where(x => !(x is IMultiMapping || x is ISingleMapping || x is IMap))
            .ForEach(x =>
            {
                Table.AddColumn(x.FieldName,
                x.Type.To(DbType.Int32),
                x.MaxLength,
                !x.NotNull,
                x.AutoIncrement,
                x.Index,
                false,
                x.Unique,
                "",
                "",
                "");
            });
 }
Beispiel #25
0
 /// <summary>
 /// Adds this instance to the table.
 /// </summary>
 /// <param name="table">The table.</param>
 public void AddToTable(ITable table) => table.AddColumn <long>(ColumnName, System.Data.DbType.Int64, identity: true, index: true, primaryKey: true);
 /// <summary>
 /// Setups the columns.
 /// </summary>
 /// <param name="table">The table.</param>
 /// <param name="item">The item.</param>
 private static void SetupColumns(ITable table, dynamic item)
 {
     if (item == null)
         throw new ArgumentNullException(nameof(item));
     if (table == null)
         throw new ArgumentNullException(nameof(table));
     if (table.ContainsColumn(item.Column))
     {
         table.AddForeignKey(item.Column, item.FOREIGN_KEY_TABLE, item.FOREIGN_KEY_COLUMN);
     }
     else
     {
         table.AddColumn<string>(item.Column,
             Utilities.DataTypes.TypeConversionExtensions.To(Utilities.DataTypes.TypeConversionExtensions.To<string, SqlDbType>(item.COLUMN_TYPE), DbType.Int32),
             (item.COLUMN_TYPE == "nvarchar") ? item.MAX_LENGTH / 2 : item.MAX_LENGTH,
             item.IS_NULLABLE,
             item.IS_IDENTITY,
             item.IS_INDEX != 0,
             !string.IsNullOrEmpty(item.PRIMARY_KEY),
             !string.IsNullOrEmpty(item.UNIQUE),
             item.FOREIGN_KEY_TABLE,
             item.FOREIGN_KEY_COLUMN,
             item.DEFAULT_VALUE);
     }
 }
        private void GetColumns(ITable table)
        {
            Type uniDBType = typeof(SQLServer.UniDbTypes);
            string cleanTableName = table.Name.Replace("'", "''");

            if (!connector.ColumnsBySchema.ContainsKey(table.Schema))
                return;

            if (!connector.ColumnsBySchema[table.Schema].ContainsKey(cleanTableName))
                return;

            List<DataRow> columnRows = connector.ColumnsBySchema[table.Schema][cleanTableName];

            foreach (DataRow columnRow in columnRows)
            {
                bool isReadOnly = false;

                if (Slyce.Common.Utility.StringsAreEqual((string)columnRow["DATA_TYPE"], "timestamp", false))
                {
                    isReadOnly = true;
                }
                Column column = new Column();
                column.Name = (string)columnRow["COLUMN_NAME"];
                column.IsUserDefined = false;
                column.Parent = table;
                column.IsIdentity = columnRow["IsIdentity"] is DBNull ? false : (Convert.ToInt32(columnRow["IsIdentity"])) == 1;
                column.OrdinalPosition = Convert.ToInt32(columnRow["ORDINAL_POSITION"]);
                column.IsNullable = ((string)columnRow["IS_NULLABLE"]).StartsWith("Y", StringComparison.InvariantCultureIgnoreCase);
                column.Precision = columnRow.IsNull("NUMERIC_PRECISION") ? 0 : Convert.ToInt32(columnRow["NUMERIC_PRECISION"]);
                column.Scale = columnRow.IsNull("NUMERIC_SCALE") ? 0 : Convert.ToInt32(columnRow["NUMERIC_SCALE"]);
                column.OriginalDataType = (string)columnRow["DATA_TYPE"];
                column.Size = columnRow.IsNull("CHARACTER_MAXIMUM_LENGTH") //|| column.Datatype == "ntext" || column.Datatype == "text" // ntext/text returns useless length
                                ? 0
                                : Convert.ToInt64(columnRow["CHARACTER_MAXIMUM_LENGTH"]);
                column.InPrimaryKey = connector.DoesColumnHaveConstraint(column, "PRIMARY KEY");
                column.IsUnique = connector.DoesColumnHaveConstraint(column, "UNIQUE");
                column.Default = columnRow.IsNull("COLUMN_DEFAULT") ? "" : (string)columnRow["COLUMN_DEFAULT"];
                column.IsReadOnly = isReadOnly;

                column.ResetDefaults();

                table.AddColumn(column);
            }
        }
        private static IColumn CloneColumn(ITable primaryTable, ITable foreignTable, IColumn column, string columnNamePrefix)
        {
            var newColumn = column.Clone();
            var name = columnNamePrefix + primaryTable.Name + "_" + column.Name;
            newColumn.Name = name.GetNextName(foreignTable.Columns.Select(c => c.Name));

            foreignTable.AddColumn(newColumn);

            return newColumn;
        }
 private static void SetupProperties(ITable Table, IMapping Mapping)
 {
     Contract.Requires<ArgumentNullException>(Mapping != null, "Mapping");
     Contract.Requires<ArgumentNullException>(Table != null, "Table");
     Contract.Requires<ArgumentNullException>(Mapping.IDProperties != null, "Mapping.IDProperties");
     foreach (IProperty Property in Mapping.IDProperties)
     {
         Table.AddColumn(Property.FieldName,
             Property.Type.To(DbType.Int32),
             Property.MaxLength,
             Property.NotNull,
             Property.AutoIncrement,
             Property.Index,
             true,
             Property.Unique,
             "",
             "",
             "");
     }
     foreach (IProperty Property in Mapping.Properties)
     {
         if (!(Property is IManyToMany || Property is IManyToOne || Property is IMap || Property is IIEnumerableManyToOne || Property is IListManyToMany || Property is IListManyToOne))
         {
             Table.AddColumn(Property.FieldName,
             Property.Type.To(DbType.Int32),
             Property.MaxLength,
             !Property.NotNull,
             Property.AutoIncrement,
             Property.Index,
             false,
             Property.Unique,
             "",
             "",
             "");
         }
     }
 }
 /// <summary>
 /// Setups the stored procedures.
 /// </summary>
 /// <param name="storedProcedure">The stored procedure.</param>
 /// <param name="item">The item.</param>
 private static void SetupStoredProcedures(ITable storedProcedure, dynamic item)
 {
     if (storedProcedure == null)
         throw new ArgumentNullException(nameof(storedProcedure));
     if (item == null)
         throw new ArgumentNullException(nameof(item));
     string Type = item.TYPE;
     string Name = item.NAME;
     int Length = item.LENGTH;
     if (Type == "nvarchar")
         Length /= 2;
     string Default = item.DEFAULT_VALUE;
     storedProcedure.AddColumn<string>(Name, Type.To<string, SqlDbType>().To(DbType.Int32), Length, DefaultValue: Default);
 }