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

C# Model.ColumnModel类代码示例

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

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



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

示例1: IsNarrowerThan_should_return_true_when_max_length_narrower

        public void IsNarrowerThan_should_return_true_when_max_length_narrower()
        {
            var columnModel1 = new ColumnModel(PrimitiveTypeKind.String)
                {
                    MaxLength = 1
                };
            var columnModel2 = new ColumnModel(PrimitiveTypeKind.String)
                {
                    MaxLength = 2
                };

            Assert.True(columnModel1.IsNarrowerThan(columnModel2, _providerManifest));

            columnModel1 = new ColumnModel(PrimitiveTypeKind.String)
                {
                    MaxLength = 1
                };
            columnModel2 = new ColumnModel(PrimitiveTypeKind.String);

            Assert.True(columnModel1.IsNarrowerThan(columnModel2, _providerManifest));

            columnModel1 = new ColumnModel(PrimitiveTypeKind.String);
            columnModel2 = new ColumnModel(PrimitiveTypeKind.String)
                {
                    MaxLength = 1
                };

            Assert.False(columnModel1.IsNarrowerThan(columnModel2, _providerManifest));
        }
开发者ID:christiandpena,项目名称:entityframework,代码行数:29,代码来源:ColumnModelTests.cs


示例2: AddDefaultValue

 private static void AddDefaultValue(ColumnModel Column)
 {
     if (Column.Annotations.Any(o => o.Key == "DefaultValue"))
     {
         Column.DefaultValueSql = Column.Annotations["DefaultValue"].NewValue.ToString();
     }
 }
开发者ID:Infro-CommonLibrary,项目名称:CommonCSharp,代码行数:7,代码来源:ExtendedSqlServerMigrationSqlGenerator.cs


示例3: Can_get_and_set_column_properties

        public void Can_get_and_set_column_properties()
        {
            var column = new ColumnModel(PrimitiveTypeKind.Guid)
                {
                    Name = "C",
                    IsNullable = true,
                    IsIdentity = true,
                    IsFixedLength = true,
                    IsUnicode = true,
                    MaxLength = 42,
                    Precision = 23,
                    Scale = 1,
                    StoreType = "foobar"
                };

            Assert.Equal("C", column.Name);
            Assert.Equal(PrimitiveTypeKind.Guid, column.Type);
            Assert.True(column.IsNullable.Value);
            Assert.True(column.IsIdentity);
            Assert.True(column.IsFixedLength.Value);
            Assert.True(column.IsUnicode.Value);
            Assert.Equal(42, column.MaxLength);
            Assert.Equal((byte)23, column.Precision);
            Assert.Equal((byte)1, column.Scale);
            Assert.Equal("foobar", column.StoreType);
        }
开发者ID:WangWilliam,项目名称:EntityFramework5,代码行数:26,代码来源:ColumnModelTests.cs


示例4: IsNarrowerThan_should_return_true_when_nullable_narrower

        public void IsNarrowerThan_should_return_true_when_nullable_narrower()
        {
            var columnModel1 = new ColumnModel(PrimitiveTypeKind.String)
                {
                    IsNullable = false
                };
            var columnModel2 = new ColumnModel(PrimitiveTypeKind.String)
                {
                    IsNullable = true
                };

            Assert.True(columnModel1.IsNarrowerThan(columnModel2, _providerManifest));

            columnModel1 = new ColumnModel(PrimitiveTypeKind.String)
                {
                    IsNullable = false
                };
            columnModel2 = new ColumnModel(PrimitiveTypeKind.String);

            Assert.True(columnModel1.IsNarrowerThan(columnModel2, _providerManifest));

            columnModel1 = new ColumnModel(PrimitiveTypeKind.String);
            columnModel2 = new ColumnModel(PrimitiveTypeKind.String)
                {
                    IsNullable = false
                };

            Assert.False(columnModel1.IsNarrowerThan(columnModel2, _providerManifest));
        }
开发者ID:christiandpena,项目名称:entityframework,代码行数:29,代码来源:ColumnModelTests.cs


示例5: Inverse_should_produce_change_column_operation

        public void Inverse_should_produce_change_column_operation()
        {
            var column = new ColumnModel(PrimitiveTypeKind.Boolean);
            var inverse = new AlterColumnOperation("T", column, isDestructiveChange: false);
            var alterColumnOperation = new AlterColumnOperation("T", column, isDestructiveChange: false, inverse: inverse);

            Assert.Same(inverse, alterColumnOperation.Inverse);
        }
开发者ID:christiandpena,项目名称:entityframework,代码行数:8,代码来源:AlterColumnOperationTests.cs


示例6: Can_get_and_set_table_and_column_info

        public void Can_get_and_set_table_and_column_info()
        {
            var column = new ColumnModel(PrimitiveTypeKind.Boolean);
            var alterColumnOperation = new AlterColumnOperation("T", column, isDestructiveChange: false);

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


示例7: 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


示例8: AddColumnOperation

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

            _table = table;
            _column = column;
        }
开发者ID:jimmy00784,项目名称:entityframework,代码行数:9,代码来源:AddColumnOperation.cs


示例9: AddColumnOperation

        public AddColumnOperation(string table, ColumnModel column, object anonymousArguments = null)
            : base(anonymousArguments)
        {
            Check.NotEmpty(table, "table");
            Check.NotNull(column, "column");

            _table = table;
            _column = column;
        }
开发者ID:jwanagel,项目名称:jjwtest,代码行数:9,代码来源:AddColumnOperation.cs


示例10: AlterColumnOperation

        public AlterColumnOperation(
            string table, ColumnModel column, bool isDestructiveChange, AlterColumnOperation inverse,
            object anonymousArguments = null)
            : this(table, column, isDestructiveChange, anonymousArguments)
        {
            Check.NotNull(inverse, "inverse");

            _inverse = inverse;
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:9,代码来源:AlterColumnOperation.cs


示例11: AlterColumnOperation

        public AlterColumnOperation(
            string table, ColumnModel column, bool isDestructiveChange, AlterColumnOperation inverse,
            object anonymousArguments = null)
            : this(table, column, isDestructiveChange, anonymousArguments)
        {
            //Contract.Requires(inverse != null);

            _inverse = inverse;
        }
开发者ID:jimmy00784,项目名称:entityframework,代码行数:9,代码来源:AlterColumnOperation.cs


示例12: 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


示例13: BuildColumnType

        protected override string BuildColumnType(ColumnModel columnModel)
        {
            if (columnModel == null)
            {
                throw new ArgumentNullException("columnModel");
            }

            TableColumnType tableColumnType = this.GetTableColumnType(columnModel);
            if (tableColumnType != TableColumnType.None)
            {
                this.UpdateTableColumn(columnModel, tableColumnType);
            }

            return base.BuildColumnType(columnModel);
        }
开发者ID:RossMerr,项目名称:azure-mobile-apps-net-server,代码行数:15,代码来源:EntityTableSqlGenerator.cs


示例14: 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


示例15: Can_get_and_set_annotations

        public void Can_get_and_set_annotations()
        {
            var column = new ColumnModel(PrimitiveTypeKind.Guid);

            Assert.Empty(column.Annotations);

            column.Annotations = new Dictionary<string, AnnotationValues> { { "A1", new AnnotationValues("V1", "V2") } };

            Assert.Equal("V1", column.Annotations["A1"].OldValue);
            Assert.Equal("V2", column.Annotations["A1"].NewValue);

            column.Annotations = null;

            Assert.Empty(column.Annotations);
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:15,代码来源:ColumnModelTests.cs


示例16: 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


示例17: 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


示例18: 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


示例19: Generate

        protected override void Generate(ColumnModel column, IndentedTextWriter writer)
        {
            writer.Write(Quote(column.Name));
            writer.Write(" ");
            writer.Write(BuildColumnType(column));

            var collation = TryGetCollation(column.Annotations);
            if (collation != null && column.ClrType == typeof(string))
            {
                writer.Write(" COLLATE " + collation.CollationName + " ");
            }

            if ((column.IsNullable != null)
                && !column.IsNullable.Value)
            {
                writer.Write(" NOT NULL");
            }

            if (column.DefaultValue != null)
            {
                writer.Write(" DEFAULT ");
                writer.Write(Generate((dynamic)column.DefaultValue));
            }
            else if (!string.IsNullOrWhiteSpace(column.DefaultValueSql))
            {
                writer.Write(" DEFAULT ");
                writer.Write(column.DefaultValueSql);
            }
            else if (column.IsIdentity)
            {
                if ((column.Type == PrimitiveTypeKind.Guid)
                    && (column.DefaultValue == null))
                {
                    writer.Write(" DEFAULT " + GuidColumnDefault);
                }
                else
                {
                    writer.Write(" IDENTITY");
                }
            }
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:41,代码来源:SqlServerMigrationSqlGeneratorWtihCollations.cs


示例20: GenerateAlterDecimalColumn

        public void GenerateAlterDecimalColumn(bool? nullable, string contain, string notContain)
        {
            var migrationProvider = new PostgreSqlMigrationSqlGenerator();

            var column = new ColumnModel(PrimitiveTypeKind.Decimal)
            {
                Name = "C",
                IsNullable = nullable
            };

            var alterColumnOperation = new AlterColumnOperation("dbo.T", column, false);

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

            const string returnSqlBase = "ALTER TABLE \"dbo\".\"T\" ALTER COLUMN \"C\" ";

            Assert.IsNotNull(sql);
            Assert.True(sql.Contains(returnSqlBase));
            Assert.True(sql.Contains(returnSqlBase + "TYPE decimal"));
            Assert.True(sql.Contains(returnSqlBase + contain));
            Assert.False(sql.Contains(returnSqlBase + notContain));
        }
开发者ID:darionato,项目名称:PostgreSqlMigrationSqlGenerator,代码行数:22,代码来源:PostgreSqlMigrationSqlGeneretorTest.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# Model.CreateTableOperation类代码示例发布时间:2022-05-26
下一篇:
C# Model.AddPrimaryKeyOperation类代码示例发布时间: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