• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Model.AddColumnOperation类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: AddColumnOperationMigration

    public void AddColumnOperationMigration()
    {
      var migrationOperations = new List<MigrationOperation>();

      if (ProviderManifest == null)
      ProviderManifest = new MySqlProviderManifest(Version.ToString());

      TypeUsage tu = TypeUsage.CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32));
      TypeUsage result = ProviderManifest.GetStoreType(tu);

      var intColumn = new ColumnModel(PrimitiveTypeKind.Int32, result)
      {
        Name = "TotalPosts",
        IsNullable = false
      };

      var addColumnMigratioOperation = new AddColumnOperation("Blogs", intColumn);
      migrationOperations.Add(addColumnMigratioOperation);

      using (BlogContext context = new BlogContext())
      {
        if (context.Database.Exists()) context.Database.Delete();
        context.Database.Create();        
        
        using (MySqlConnection conn = new MySqlConnection(context.Database.Connection.ConnectionString))
        {
          if (conn.State == System.Data.ConnectionState.Closed) conn.Open();
          Assert.AreEqual(true, GenerateAndExecuteMySQLStatements(migrationOperations));
          
          MySqlCommand query = new MySqlCommand("Select Column_name, Is_Nullable, Data_Type from information_schema.Columns where table_schema ='" + conn.Database + "' and table_name = 'Blogs' and column_name ='TotalPosts'" , conn);
          MySqlDataReader reader = query.ExecuteReader();
          while (reader.Read())
          {
            Assert.AreEqual("TotalPosts", reader[0].ToString());
            Assert.AreEqual("NO", reader[1].ToString());
            Assert.AreEqual("int", reader[2].ToString());
          }
          reader.Close();
          conn.Close();
        }
      }        
    }
开发者ID:eeeee,项目名称:mysql-connector-net,代码行数:42,代码来源:MySqlMigrationsTests.cs


示例17: Generate

 protected override void Generate(AddColumnOperation addColumnOperation, IndentedTextWriter writer)
 {
     var add = new AddColumnOperation(TrimSchemaPrefix(addColumnOperation.Table), addColumnOperation.Column);
       base.Generate(add, writer);
 }
开发者ID:schivei,项目名称:mysql-connector-net,代码行数:5,代码来源:MySqlMigrationSqlGenerator.cs


示例18: Generate

        /// <summary>
        /// Generates code to perform an <see cref="AddColumnOperation" />.
        /// </summary>
        /// <param name="addColumnOperation"> The operation to generate code for. </param>
        /// <param name="writer"> Text writer to add the generated code to. </param>
        protected virtual void Generate(AddColumnOperation addColumnOperation, IndentedTextWriter writer)
        {
            Check.NotNull(addColumnOperation, "addColumnOperation");
            Check.NotNull(writer, "writer");

            writer.Write("AddColumn(");
            writer.Write(Quote(addColumnOperation.Table));
            writer.Write(", ");
            writer.Write(Quote(addColumnOperation.Column.Name));
            writer.Write(", Function(c)");
            Generate(addColumnOperation.Column, writer);
            writer.WriteLine(")");
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:18,代码来源:VisualBasicMigrationCodeGenerator.cs


示例19: Generate

        /// <summary>
        /// Generates SQL for a <see cref="AddColumnOperation" />.
        /// Generated SQL should be added using the Statement method.
        /// </summary>
        /// <param name="addColumnOperation"> The operation to produce SQL for. </param>
        protected virtual void Generate(AddColumnOperation addColumnOperation)
        {
            Check.NotNull(addColumnOperation, "addColumnOperation");

            using (var writer = Writer())
            {
                writer.Write("ALTER TABLE ");
                writer.Write(Name(addColumnOperation.Table));
                writer.Write(" ADD ");

                var column = addColumnOperation.Column;

                Generate(column, writer);

                if ((column.IsNullable != null)
                    && !column.IsNullable.Value
                    && (column.DefaultValue == null)
                    && (string.IsNullOrWhiteSpace(column.DefaultValueSql))
                    && !column.IsIdentity
                    && !column.IsTimestamp
                    && !column.StoreType.EqualsIgnoreCase("rowversion")
                    && !column.StoreType.EqualsIgnoreCase("timestamp"))
                {
                    writer.Write(" DEFAULT ");

                    if (column.Type == PrimitiveTypeKind.DateTime)
                    {
                        writer.Write(Generate(DateTime.Parse("1900-01-01 00:00:00", CultureInfo.InvariantCulture)));
                    }
                    else
                    {
                        writer.Write(Generate((dynamic)column.ClrDefaultValue));
                    }
                }

                Statement(writer);
            }
        }
开发者ID:aspnet,项目名称:EntityFramework6,代码行数:43,代码来源:SqlServerMigrationSqlGenerator.cs


示例20: HistoryRebuildOperationSequence

 private HistoryRebuildOperationSequence(
     AddColumnOperation addColumnOperation,
     DropPrimaryKeyOperation dropPrimaryKeyOperation)
     : base(null)
 {
     AddColumnOperation = addColumnOperation;
     DropPrimaryKeyOperation = dropPrimaryKeyOperation;
 }
开发者ID:aspnet,项目名称:EntityFramework6,代码行数:8,代码来源:SqlServerMigrationSqlGenerator.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Model.AddForeignKeyOperation类代码示例发布时间:2022-05-26
下一篇:
C# Infrastructure.EdmModelDiffer类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap