当前位置: 首页>>代码示例>>C#>>正文


C# DatabaseTable.AddColumn方法代码示例

本文整理汇总了C#中DatabaseSchemaReader.DataSchema.DatabaseTable.AddColumn方法的典型用法代码示例。如果您正苦于以下问题:C# DatabaseTable.AddColumn方法的具体用法?C# DatabaseTable.AddColumn怎么用?C# DatabaseTable.AddColumn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DatabaseSchemaReader.DataSchema.DatabaseTable的用法示例。


在下文中一共展示了DatabaseTable.AddColumn方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TriggerWithNoQuotes

        public void TriggerWithNoQuotes()
        {
            //arrange
            var osr = new OracleSchemaReader(ConnectionStrings.OracleHr, "System.Data.OracleClient");
            var dt = new DatabaseTable();
            dt
                .AddColumn("ID")
                .AddPrimaryKey()
                .AddColumn("NAME");
            dt.Triggers.Add(new DatabaseTrigger
            {
                //with spaces, line breaks
                TriggerBody = @"BEGIN
    SELECT MY_SEQ.NEXTVAL
    INTO :NEW.ID
    FROM DUAL;
END;"
            });

            //act
            osr.PostProcessing(dt);

            //assert
            Assert.IsTrue(dt.HasAutoNumberColumn);
        }
开发者ID:Petran15,项目名称:dbschemareader,代码行数:25,代码来源:OracleSchemaReaderTest.cs

示例2: TestPostgreSqlColumnDefaults

        public void TestPostgreSqlColumnDefaults()
        {
            //MigrationGenerator does not output default values for columns
            //https://github.com/martinjw/dbschemareader/issues/11

            //arrange
            var gen = new DdlGeneratorFactory(SqlType.PostgreSql).MigrationGenerator();
            gen.IncludeSchema = false;

            var pkSeqName = "Seq_PK_Generator";
            var pkSeq = new DatabaseSequence()
            {
                Name = pkSeqName,
                MinimumValue = 1,
                IncrementBy = 1,
            };

            //gen.AddSequence(pkSeq).Replace(";", " CACHE;");

            var newTable = new DatabaseTable { Name = "TestTable" };

            var idColumn = newTable.AddColumn("Id", DbType.Int64);
            idColumn.AddPrimaryKey("PK_TestTable");
            idColumn.DefaultValue = $"nextval('{pkSeqName}')";
            var summaryColumn = newTable.AddColumn("Summary", DbType.String);
            summaryColumn.Length = 100;

            //act
            var ddl = gen.AddTable(newTable);

            //assert

            //expected
            /*
            CREATE SEQUENCE "Seq_PK_Generator" INCREMENT BY 1 MINVALUE 1 CACHE;

            CREATE TABLE "TestTable"
            (
              "Id" BIGINT NOT NULL, --default value missing
              "Summary" VARCHAR (100)  NOT NULL
            );
            ALTER TABLE "TestTable" ADD CONSTRAINT "PK_TestTable" PRIMARY KEY ("Id");
             */

            Assert.IsTrue(ddl.IndexOf("BIGINT NOT NULL DEFAULT nextval('Seq_PK_Generator'),", StringComparison.OrdinalIgnoreCase) != -1, "default value should be included");
        }
开发者ID:shiningrise,项目名称:dbschemareader,代码行数:46,代码来源:MigrationAddColumnDefaults.cs

示例3: CreateTable

        private static DatabaseTable CreateTable()
        {
            var table = new DatabaseTable();
            table.Name = "Test";
            table.AddColumn("A", DbType.Int32).AddPrimaryKey("PK_TEST")
                .AddColumn("B", DbType.Int32)
                .AddColumn("C", DbType.String).AddLength(10).AddNullable();

            return table;
        }
开发者ID:Petran15,项目名称:dbschemareader,代码行数:10,代码来源:CompareTablesTest.cs

示例4: NoTriggers

        public void NoTriggers()
        {
            //arrange
            var osr = new OracleSchemaReader(ConnectionStrings.OracleHr, "System.Data.OracleClient");
            var dt = new DatabaseTable();
            dt
                .AddColumn("ID")
                .AddPrimaryKey()
                .AddColumn("NAME");

            //act
            osr.PostProcessing(dt);

            //assert
            Assert.IsFalse(dt.HasAutoNumberColumn);

        }
开发者ID:Petran15,项目名称:dbschemareader,代码行数:17,代码来源:OracleSchemaReaderTest.cs

示例5: TestIndex

        public void TestIndex()
        {
            //arrange
            var settings = new CodeWriterSettings();
            settings.CodeTarget = CodeTarget.PocoEntityCodeFirst;
            settings.WriteCodeFirstIndexAttribute = true;

            var classBuilder = new ClassBuilder();
            var table = new DatabaseTable { Name = "Test" };
            var nameColumn = table.AddColumn<int>("Id").AddPrimaryKey()
                .AddColumn<string>("Name").AddNullable().AddIndex("IX_NAME");

            var target = new DataAnnotationWriter(true, settings);

            //act
            target.Write(classBuilder, nameColumn);
            var result = classBuilder.ToString().Trim(); //ignore lines

            //assert
            Assert.AreEqual("[Index(\"IX_NAME\")]", result);
        }
开发者ID:shiningrise,项目名称:dbschemareader,代码行数:21,代码来源:DataAnnotationWriterTest.cs

示例6: TriggerWithQuotes

        public void TriggerWithQuotes()
        {
            //arrange
            var osr = new OracleSchemaReader(ConnectionStrings.OracleHr, "System.Data.OracleClient");
            var dt = new DatabaseTable();
            dt
                .AddColumn("ID")
                .AddPrimaryKey()
                .AddColumn("NAME");
            dt.Triggers.Add(new DatabaseTrigger
            {
                //generated by SqlDeveloper
                TriggerBody = @"CREATE OR REPLACE TRIGGER ""DB"".""MYTRIGGER"" before insert on ""DB"".""TABLE1""    for each row begin     if inserting then       if :NEW.""ID"" is null then          select MY_SEQ.nextval into :NEW.""ID"" from dual;       end if;    end if; end;"
            });

            //act
            osr.PostProcessing(dt);

            //assert
            Assert.IsTrue(dt.HasAutoNumberColumn);
        }
开发者ID:Petran15,项目名称:dbschemareader,代码行数:21,代码来源:OracleSchemaReaderTest.cs

示例7: ReadProperty

        private void ReadProperty(XElement property, DatabaseTable table)
        {
            var name = (string)property.Attribute("Name");
            var type = (string)property.Attribute("Type");

            var nullable = (bool?)property.Attribute("Nullable") ?? true;
            var maxLength = (int?)property.Attribute("MaxLength");
            var precision = (int?)property.Attribute("Precision");
            var scale = (int?)property.Attribute("Scale");
            var defaultValue = (string)property.Attribute("DefaultValue");
            var storeGeneratedPattern = (string)property.Attribute("StoreGeneratedPattern");

            if (type.EndsWith("(max)", StringComparison.OrdinalIgnoreCase))
            {
                type = type.Substring(0, type.Length - 5);
                maxLength = -1;
            }
            //timestamp is a varbinary(8) computed
            if (type == "binary" && maxLength == 8 && (string)property.Attribute("StoreGeneratedPattern") == "Computed")
            {
                type = "timestamp";
                maxLength = null;
            }

            var column = table.AddColumn(name, type);
            column.DefaultValue = defaultValue;
            column.Length = maxLength;
            column.Precision = precision;
            column.Scale = scale;
            column.Nullable = nullable;

            if (storeGeneratedPattern == "Identity") column.IsAutoNumber = true;

            FixColumn(column);

        }
开发者ID:Petran15,项目名称:dbschemareader,代码行数:36,代码来源:EntityFrameworkImporter.cs

示例8: TestIndexNotNeededForPrimaryKey

        public void TestIndexNotNeededForPrimaryKey()
        {
            //arrange
            var settings = new CodeWriterSettings();
            settings.CodeTarget = CodeTarget.PocoEntityCodeFirst;
            settings.WriteCodeFirstIndexAttribute = true;

            var classBuilder = new ClassBuilder();
            var table = new DatabaseTable { Name = "Test" };
            table.AddColumn<int>("Id").AddPrimaryKey().AddIndex("PK_TEST")
                .AddColumn<string>("Category").AddNullable()
                .AddColumn<string>("Name").AddNullable().AddIndex("IX_NAME")
                ;
            var idColumn = table.PrimaryKeyColumn;

            var target = new DataAnnotationWriter(true, settings);

            //act
            target.Write(classBuilder, idColumn);
            var result = classBuilder.ToString().Trim(); //ignore lines

            //assert
            Assert.IsTrue(result.IndexOf("[Index", StringComparison.OrdinalIgnoreCase) == -1, "Should be just[Key]");
        }
开发者ID:Petran15,项目名称:dbschemareader,代码行数:24,代码来源:DataAnnotationWriterTest.cs


注:本文中的DatabaseSchemaReader.DataSchema.DatabaseTable.AddColumn方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。