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


C# Model.AddColumnOperation类代码示例

本文整理汇总了C#中System.Data.Entity.Migrations.Model.AddColumnOperation的典型用法代码示例。如果您正苦于以下问题:C# AddColumnOperation类的具体用法?C# AddColumnOperation怎么用?C# AddColumnOperation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


AddColumnOperation类属于System.Data.Entity.Migrations.Model命名空间,在下文中一共展示了AddColumnOperation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Generate

        protected override void Generate(AddColumnOperation addColumnOperation)
        {
            SetCreatedUtcColumn(addColumnOperation.Column);
            AddDefaultValue(addColumnOperation.Column);

            base.Generate(addColumnOperation);
        }
开发者ID:Infro-CommonLibrary,项目名称:CommonCSharp,代码行数:7,代码来源:ExtendedSqlServerMigrationSqlGenerator.cs

示例2: Generate

        protected virtual IEnumerable<MigrationStatement> Generate(AddColumnOperation operation)
        {
            using (var writer = SqlWriter())
            {
                writer.Write("ALTER TABLE ");
                writer.Write(Quote(operation.Table));
                writer.Write(" ADD ");
                var column = operation.Column;
                writer.Write(Generate(column));
                if (column.IsNullable != null
                    && !column.IsNullable.Value
                    && column.DefaultValue == null
                    && string.IsNullOrWhiteSpace(column.DefaultValueSql)
                    && !column.IsIdentity
                    && !column.IsTimestamp)
                {
                    writer.Write(" DEFAULT ");

                    if (column.Type == PrimitiveTypeKind.DateTime)
                    {
                        writer.Write(WriteValue(DateTime.Parse("1970-01-01 00:00:00", CultureInfo.InvariantCulture)));
                    }
                    else
                    {
                        writer.Write(WriteValue((dynamic)column.ClrDefaultValue));
                    }
                }
                yield return Statement(writer);
            }
        }
开发者ID:helluvamatt,项目名称:nuodb-dotnet,代码行数:30,代码来源:NuoDbMigrationSqlGenerator.cs

示例3: Generate_should_output_invariant_decimals_when_non_invariant_culture

        public void Generate_should_output_invariant_decimals_when_non_invariant_culture()
        {
            var migrationProvider = new SqlServerMigrationSqlGenerator();

            var addColumnOperation
                = new AddColumnOperation(
                    "T",
                    new ColumnModel(PrimitiveTypeKind.Binary)
                        {
                            Name = "C",
                            DefaultValue = 123.45m
                        });

            var lastCulture = Thread.CurrentThread.CurrentCulture;

            try
            {
                Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("nl-NL");

                var sql = migrationProvider.Generate(new[] { addColumnOperation }, "2008").Join(s => s.Sql, Environment.NewLine);

                Assert.Contains("ALTER TABLE [T] ADD [C] [varbinary](max) DEFAULT 123.45", sql);
            }
            finally
            {
                Thread.CurrentThread.CurrentCulture = lastCulture;
            }
        }
开发者ID:christiandpena,项目名称:entityframework,代码行数:28,代码来源:SqlServerMigrationSqlGeneratorTests.cs

示例4: Inverse_should_produce_drop_column_operation

        public void Inverse_should_produce_drop_column_operation()
        {
            var inverse = new AddColumnOperation("T", new ColumnModel(PrimitiveTypeKind.Binary));
            var dropColumnOperation = new DropColumnOperation("T", "c", inverse);

            Assert.Same(inverse, dropColumnOperation.Inverse);
        }
开发者ID:jimmy00784,项目名称:entityframework,代码行数:7,代码来源:DropColumnOperationTests.cs

示例5: Can_get_and_set_table_and_column_info

        public void Can_get_and_set_table_and_column_info()
        {
            var column = new ColumnModel(PrimitiveTypeKind.Decimal);
            var addColumnOperation = new AddColumnOperation("T", column);

            Assert.Equal("T", addColumnOperation.Table);
            Assert.Same(column, addColumnOperation.Column);
        }
开发者ID:christiandpena,项目名称:entityframework,代码行数:8,代码来源:AddColumnOperationTests.cs

示例6: Generate

    protected virtual MigrationStatement Generate(AddColumnOperation op)
    {
      if (op == null) return null;

      MigrationStatement stmt = new MigrationStatement();
      stmt.Sql = string.Format("alter table `{0}` add column `{1}`",
        op.Table, op.Column.Name) + " " + Generate(op.Column);
      return stmt;
    }
开发者ID:brunolauze,项目名称:mysql-connector-net-6,代码行数:9,代码来源:MySqlMigrationSqlGenerator.cs

示例7: Inverse_should_produce_drop_column_operation

        public void Inverse_should_produce_drop_column_operation()
        {
            var column = new ColumnModel(PrimitiveTypeKind.Decimal) { Name = "C" };
            var addColumnOperation = new AddColumnOperation("T", column);

            var dropColumnOperation = (DropColumnOperation)addColumnOperation.Inverse;

            Assert.Equal("C", dropColumnOperation.Name);
            Assert.Equal("T", dropColumnOperation.Table);
        }
开发者ID:jimmy00784,项目名称:entityframework,代码行数:10,代码来源:AddColumnOperationTests.cs

示例8: DropColumnOperation

        public DropColumnOperation(
            string table, string name, AddColumnOperation inverse, object anonymousArguments = null)
            : base(anonymousArguments)
        {
            //Contract.Requires(!string.IsNullOrWhiteSpace(table));
            //Contract.Requires(!string.IsNullOrWhiteSpace(name));

            _table = table;
            _name = name;
            _inverse = inverse;
        }
开发者ID:jimmy00784,项目名称:entityframework,代码行数:11,代码来源:DropColumnOperation.cs

示例9: DropColumnOperation

        public DropColumnOperation(
            string table, string name, AddColumnOperation inverse, object anonymousArguments = null)
            : base(anonymousArguments)
        {
            Check.NotEmpty(table, "table");
            Check.NotEmpty(name, "name");

            _table = table;
            _name = name;
            _inverse = inverse;
        }
开发者ID:christiandpena,项目名称:entityframework,代码行数:11,代码来源:DropColumnOperation.cs

示例10: Inverse_should_return_given_AddColumnOperation

        public void Inverse_should_return_given_AddColumnOperation()
        {
            var inverse = new AddColumnOperation("T", new ColumnModel(PrimitiveTypeKind.Binary));
            var dropColumnOperation = new DropColumnOperation("T", "c", inverse);

            Assert.Same(inverse, dropColumnOperation.Inverse);

            dropColumnOperation = new DropColumnOperation("T", "c", null, inverse);

            Assert.Same(inverse, dropColumnOperation.Inverse);
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:11,代码来源:DropColumnOperationTests.cs

示例11: GenerateCanOutputAddColumnStatementWhenNonNullableAndNoDefaultProvided

        public void GenerateCanOutputAddColumnStatementWhenNonNullableAndNoDefaultProvided()
        {
            var migrationSqlGenerator = new PostgreSqlMigrationSqlGenerator();

            var column = new ColumnModel(PrimitiveTypeKind.Int32)
            {
                Name = "Bar",
                IsNullable = false
            };
            var addColumnOperation = new AddColumnOperation("Foo", column);

            var sql = migrationSqlGenerator.Generate(new[] { addColumnOperation }, "9.2").Join(s => s.Sql, Environment.NewLine);

            Assert.True(sql.Contains("ALTER TABLE \"Foo\" ADD \"Bar\" integer NOT NULL DEFAULT 0"));
        }
开发者ID:darionato,项目名称:PostgreSqlMigrationSqlGenerator,代码行数:15,代码来源:PostgreSqlMigrationSqlGeneretorTest.cs

示例12: GenerateCanOutputAddColumnStatement

        public void GenerateCanOutputAddColumnStatement(PrimitiveTypeKind type, string typeName)
        {
            var migrationSqlGenerator = new PostgreSqlMigrationSqlGenerator();

            var column = new ColumnModel(type)
            {
                Name = "Bar",
                IsIdentity = true
            };
            var addColumnOperation = new AddColumnOperation("Foo", column);

            var sql = migrationSqlGenerator.Generate(
                new[] { addColumnOperation }, "9.2").Join(s => s.Sql, Environment.NewLine);

            Assert.True(sql.Contains(string.Format("ALTER TABLE \"Foo\" ADD \"Bar\" {0}", typeName)));
        }
开发者ID:darionato,项目名称:PostgreSqlMigrationSqlGenerator,代码行数:16,代码来源:PostgreSqlMigrationSqlGeneretorTest.cs

示例13: Inverse_should_produce_drop_column_operation

        public void Inverse_should_produce_drop_column_operation()
        {
            var column = new ColumnModel(PrimitiveTypeKind.Decimal)
            {
                Name = "C",
                Annotations = new Dictionary<string, AnnotationValues> { { "A1", new AnnotationValues(null, "V1") } }
            };

            var addColumnOperation
                = new AddColumnOperation("T", column);

            var dropColumnOperation = (DropColumnOperation)addColumnOperation.Inverse;

            Assert.Equal("C", dropColumnOperation.Name);
            Assert.Equal("T", dropColumnOperation.Table);
            Assert.Equal("V1", dropColumnOperation.RemovedAnnotations["A1"]);
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:17,代码来源:AddColumnOperationTests.cs

示例14: Generate_can_output_add_timestamp_store_type_column_operation

        public void Generate_can_output_add_timestamp_store_type_column_operation()
        {
            var migrationProvider = new SqlServerMigrationSqlGenerator();

            var addColumnOperation
                = new AddColumnOperation(
                    "T",
                    new ColumnModel(PrimitiveTypeKind.Binary)
                    {
                        IsNullable = false,
                        Name = "C",
                        StoreType = "timestamp"
                    });

            var sql = migrationProvider.Generate(new[] { addColumnOperation }, "2008").Join(s => s.Sql, Environment.NewLine);

            Assert.True(sql.Contains("ALTER TABLE [T] ADD [C] [timestamp] NOT NULL"));
        }
开发者ID:WangWilliam,项目名称:EntityFramework5,代码行数:18,代码来源:SqlServerMigrationSqlGeneratorTests.cs

示例15: Generate_can_output_add_rowversion_store_type_column_operation

        public void Generate_can_output_add_rowversion_store_type_column_operation()
        {
            var migrationSqlGenerator = new SqlServerMigrationSqlGenerator();

            var addColumnOperation
                = new AddColumnOperation(
                    "T",
                    new ColumnModel(PrimitiveTypeKind.Binary)
                        {
                            IsNullable = false,
                            Name = "C",
                            StoreType = "RowVersion"
                        });

            var sql = migrationSqlGenerator.Generate(new[] { addColumnOperation }, "2008").Join(s => s.Sql, Environment.NewLine);

            Assert.Contains("ALTER TABLE [T] ADD [C] [RowVersion] NOT NULL", sql);
        }
开发者ID:christiandpena,项目名称:entityframework,代码行数:18,代码来源:SqlServerMigrationSqlGeneratorTests.cs


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