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

C# Design.CSharpMigrationCodeGenerator类代码示例

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

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



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

示例1: UniquifyName_should_return_unique_name_when_conflict

        public void UniquifyName_should_return_unique_name_when_conflict()
        {
            var codeGenerator = new CSharpMigrationCodeGenerator();

            var @namespace = "Migrations";

            var generatedMigration1
                = codeGenerator.Generate(
                    "201108162311111_Migration",
                    new MigrationOperation[] { },
                    "Source",
                    "Target",
                    @namespace,
                    "Migration");

            var generatedMigration2
                = codeGenerator.Generate(
                    "201108162311111_Migration1",
                    new MigrationOperation[] { },
                    "Source",
                    "Target",
                    @namespace,
                    "Migration1");

            var migrationAssembly
                = new MigrationAssembly(
                    new MigrationCompiler("cs")
                        .Compile(
                            @namespace,
                            generatedMigration1,
                            generatedMigration2),
                    @namespace);

            Assert.Equal("Migration2", migrationAssembly.UniquifyName("Migration"));
        }
开发者ID:christiandpena,项目名称:entityframework,代码行数:35,代码来源:MigrationAssemblyTests.cs


示例2: Generate_can_output_create_procedure_operations

        public void Generate_can_output_create_procedure_operations()
        {
            var createProcedureOperation
                = new CreateProcedureOperation("Foo", "SELECT ShinyHead\r\nFROM Pilkingtons");

            createProcedureOperation.Parameters.Add(
                new ParameterModel(PrimitiveTypeKind.String)
                    {
                        Name = "P'",
                        DefaultValue = "Bar",
                        IsOutParameter = true
                    });

            var codeGenerator = new CSharpMigrationCodeGenerator();

            var generatedMigration
                = codeGenerator.Generate(
                    "Migration",
                    new MigrationOperation[]
                        {
                            createProcedureOperation
                        },
                    "Source",
                    "Target",
                    "Foo",
                    "Bar");

            Assert.Equal(
                @"namespace Foo
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class Bar : DbMigration
    {
        public override void Up()
        {
            CreateStoredProcedure(
                ""Foo"",
                p => new
                    {
                        P = p.String(name: ""P'"", defaultValue: ""Bar"", outParameter: true),
                    },
                body:
                    @""SELECT ShinyHead
                      FROM Pilkingtons""
            );
            
        }
        
        public override void Down()
        {
            DropStoredProcedure(""Foo"");
        }
    }
}
",
                generatedMigration.UserCode);
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:59,代码来源:CSharpMigrationCodeGeneratorTests.cs


示例3: DbMigrationsConfiguration

        /// <summary>
        ///     Initializes a new instance of the DbMigrationsConfiguration class.
        /// </summary>
        public DbMigrationsConfiguration()
            : this(new Lazy<DbConfiguration>(() => DbConfiguration.Instance))
        {
            SetSqlGenerator("System.Data.SqlClient", new SqlServerMigrationSqlGenerator());
            SetSqlGenerator("System.Data.SqlServerCe.4.0", new SqlCeMigrationSqlGenerator());

            CodeGenerator = new CSharpMigrationCodeGenerator();
        }
开发者ID:WangWilliam,项目名称:EntityFramework5,代码行数:11,代码来源:DbMigrationsConfiguration.cs


示例4: Generate_should_output_invariant_decimals_when_non_invariant_culture

        public void Generate_should_output_invariant_decimals_when_non_invariant_culture()
        {
            var lastCulture = Thread.CurrentThread.CurrentCulture;

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

                var generatedMigration
                    = new CSharpMigrationCodeGenerator().Generate(
                        "Migration",
                        new[]
                            {
                                new AddColumnOperation(
                                    "T",
                                    new ColumnModel(PrimitiveTypeKind.Decimal)
                                        {
                                            Name = "C",
                                            DefaultValue = 123.45m
                                        })
                            },
                        "Source",
                        "Target",
                        "Foo",
                        "Bar");

                Assert.Equal(
                    @"namespace Foo
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class Bar : DbMigration
    {
        public override void Up()
        {
            AddColumn(""T"", ""C"", c => c.Decimal(defaultValue: 123.45m));
        }
        
        public override void Down()
        {
            DropColumn(""T"", ""C"");
        }
    }
}
",
                    generatedMigration.UserCode);
            }
            finally
            {
                Thread.CurrentThread.CurrentCulture = lastCulture;
            }
        }
开发者ID:jwanagel,项目名称:jjwtest,代码行数:53,代码来源:CSharpMigrationCodeGeneratorTests.cs


示例5: Generate_can_output_drop_procedure_operations

        public void Generate_can_output_drop_procedure_operations()
        {
            var codeGenerator = new CSharpMigrationCodeGenerator();

            var generatedMigration
                = codeGenerator.Generate(
                    "Migration",
                    new MigrationOperation[]
                        {
                            new DropProcedureOperation("Foo"),
                            new DropTableOperation("Bar", new CreateTableOperation("Bar"))
                        },
                    "Source",
                    "Target",
                    "Foo",
                    "Bar");

            Assert.Equal(
                @"namespace Foo
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class Bar : DbMigration
    {
        public override void Up()
        {
            DropStoredProcedure(""Foo"");
            DropTable(""Bar"");
        }
        
        public override void Down()
        {
            CreateTable(
                ""Bar"",
                c => new
                    {
                    });
            
            throw new NotSupportedException(""" + Strings.ScaffoldSprocInDownNotSupported + @""");
        }
    }
}
",
                generatedMigration.UserCode);
        }
开发者ID:christiandpena,项目名称:entityframework,代码行数:46,代码来源:CSharpMigrationCodeGeneratorTests.cs


示例6: Generate_can_output_drop_primary_key_with_explicit_name

        public void Generate_can_output_drop_primary_key_with_explicit_name()
        {
            var codeGenerator = new CSharpMigrationCodeGenerator();

            var dropPrimaryKeyOperation
                = new DropPrimaryKeyOperation
                      {
                          Table = "T",
                          Name = "PK"
                      };

            dropPrimaryKeyOperation.Columns.Add("c1");
            dropPrimaryKeyOperation.Columns.Add("c2");

            var generatedMigration
                = codeGenerator.Generate(
                    "Migration",
                    new MigrationOperation[] { dropPrimaryKeyOperation },
                    "Source",
                    "Target",
                    "Foo",
                    "Bar");

            Assert.Equal(
                @"namespace Foo
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class Bar : DbMigration
    {
        public override void Up()
        {
            DropPrimaryKey(""T"", ""PK"");
        }
        
        public override void Down()
        {
            AddPrimaryKey(""T"", new[] { ""c1"", ""c2"" }, name: ""PK"");
        }
    }
}
",
                generatedMigration.UserCode);
        }
开发者ID:junxy,项目名称:entityframework,代码行数:45,代码来源:CSharpMigrationCodeGeneratorTests.cs


示例7: MigrationIds_should_return_id_when_migration_is_valid

        public void MigrationIds_should_return_id_when_migration_is_valid()
        {
            var codeGenerator = new CSharpMigrationCodeGenerator();

            var @namespace = "Migrations";

            var generatedMigration
                = codeGenerator.Generate(
                    "201108162311111_Migration",
                    new MigrationOperation[] { },
                    "Source",
                    "Target",
                    @namespace,
                    "Migration");

            var migrationAssembly = new MigrationAssembly(
                new MigrationCompiler("cs").Compile(@namespace, generatedMigration),
                @namespace);

            Assert.Equal(1, migrationAssembly.MigrationIds.Count());
        }
开发者ID:christiandpena,项目名称:entityframework,代码行数:21,代码来源:MigrationAssemblyTests.cs


示例8: Generate_should_not_produce_lines_that_are_too_long_for_the_compiler

        public void Generate_should_not_produce_lines_that_are_too_long_for_the_compiler()
        {
            var codeGenerator = new CSharpMigrationCodeGenerator();

            var generatedMigration
                = codeGenerator.Generate(
                    "Migration",
                    new MigrationOperation[] { },
                    new string('a', 10000),
                    "Target",
                    "Foo",
                    "Bar");

            using (var stringReader = new StringReader(generatedMigration.DesignerCode))
            {
                string line;
                while ((line = stringReader.ReadLine()) != null)
                {
                    Assert.True(line.Length <= 1100);
                }
            }
        }
开发者ID:junxy,项目名称:entityframework,代码行数:22,代码来源:CSharpMigrationCodeGeneratorTests.cs


示例9: Generate_can_output_create_table_statement

        public void Generate_can_output_create_table_statement()
        {
            var createTableOperation = new CreateTableOperation("Customers");
            var idColumn = new ColumnModel(PrimitiveTypeKind.Int32)
                               {
                                   Name = "I.d",
                                   IsNullable = true,
                                   IsIdentity = true
                               };
            createTableOperation.Columns.Add(idColumn);
            createTableOperation.Columns.Add(
                new ColumnModel(PrimitiveTypeKind.String)
                    {
                        Name = "Name",
                        IsNullable = false
                    });
            createTableOperation.PrimaryKey = new AddPrimaryKeyOperation
                                                  {
                                                      Name = "MyPK"
                                                  };
            createTableOperation.PrimaryKey.Columns.Add(idColumn.Name);

            var codeGenerator = new CSharpMigrationCodeGenerator();

            var addForeignKeyOperation = new AddForeignKeyOperation
                                             {
                                                 DependentTable = "Customers",
                                                 PrincipalTable = "Blogs",
                                                 CascadeDelete = true
                                             };
            addForeignKeyOperation.DependentColumns.Add("Blog.Id");
            addForeignKeyOperation.PrincipalColumns.Add("Id");

            var generatedMigration
                = codeGenerator.Generate(
                    "Migration",
                    new MigrationOperation[]
                        {
                            createTableOperation,
                            addForeignKeyOperation,
                            addForeignKeyOperation.CreateCreateIndexOperation()
                        },
                    "Source",
                    "Target",
                    "Foo",
                    "Bar");

            Assert.Equal(
                @"namespace Foo
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class Bar : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                ""Customers"",
                c => new
                    {
                        Id = c.Int(name: ""I.d"", identity: true),
                        Name = c.String(nullable: false),
                    })
                .PrimaryKey(t => t.Id, name: ""MyPK"")
                .ForeignKey(""Blogs"", t => t.BlogId, cascadeDelete: true)
                .Index(t => t.BlogId);
            
        }
        
        public override void Down()
        {
            DropIndex(""Customers"", new[] { ""Blog.Id"" });
            DropForeignKey(""Customers"", ""Blog.Id"", ""Blogs"");
            DropTable(""Customers"");
        }
    }
}
",
                generatedMigration.UserCode);

            Assert.Equal(
                @"// <auto-generated />
namespace Foo
{
    using System.CodeDom.Compiler;
    using System.Data.Entity.Migrations;
    using System.Data.Entity.Migrations.Infrastructure;
    using System.Resources;
    
    [GeneratedCode(""EntityFramework.Migrations"", """ + typeof(DbContext).Assembly().GetInformationalVersion() + @""")]
    public sealed partial class Bar : IMigrationMetadata
    {
        private readonly ResourceManager Resources = new ResourceManager(typeof(Bar));
        
        string IMigrationMetadata.Id
        {
            get { return ""Migration""; }
        }
        
//.........这里部分代码省略.........
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:101,代码来源:CSharpMigrationCodeGeneratorTests.cs


示例10: Generate_create_table_operation_with_non_clustered_key_and_fully_configured_index

        public void Generate_create_table_operation_with_non_clustered_key_and_fully_configured_index()
        {
            var createTableOperation = new CreateTableOperation("Customers");
            
            var idColumn = new ColumnModel(PrimitiveTypeKind.Int32) { Name = "I.d" };
            createTableOperation.Columns.Add(idColumn);
            
            createTableOperation.PrimaryKey = new AddPrimaryKeyOperation
            {
                Name = "MyPK",
                IsClustered = false
            };
            createTableOperation.PrimaryKey.Columns.Add(idColumn.Name);

            var createIndexOperation = new CreateIndexOperation
            {
                Table = createTableOperation.Name, 
                Name = "MyIndex",
                IsClustered = true,
                IsUnique = true
            };
            createIndexOperation.Columns.Add(idColumn.Name);

            var generatedMigration
                = new CSharpMigrationCodeGenerator().Generate(
                    "Migration",
                    new MigrationOperation[]
                        {
                            createTableOperation,
                            createIndexOperation
                        },
                    "Source",
                    "Target",
                    "Foo",
                    "Bar");

            Assert.Equal(
                @"namespace Foo
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class Bar : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                ""Customers"",
                c => new
                    {
                        Id = c.Int(name: ""I.d""),
                    })
                .PrimaryKey(t => t.Id, name: ""MyPK"", clustered: false)
                .Index(t => t.Id, unique: true, clustered: true, name: ""MyIndex"");
            
        }
        
        public override void Down()
        {
            DropIndex(""Customers"", ""MyIndex"");
            DropTable(""Customers"");
        }
    }
}
",
                generatedMigration.UserCode);
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:67,代码来源:CSharpMigrationCodeGeneratorTests.cs


示例11: Generate_can_output_drop_column

        public void Generate_can_output_drop_column()
        {
            var codeGenerator = new CSharpMigrationCodeGenerator();

            var dropColumnOperation = new DropColumnOperation("Customers", "Foo");

            var generatedMigration
                = codeGenerator.Generate(
                    "Migration",
                    new MigrationOperation[] { dropColumnOperation },
                    "Source",
                    "Target",
                    "Foo",
                    "Bar");

            Assert.Equal(
                @"namespace Foo
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class Bar : DbMigration
    {
        public override void Up()
        {
            DropColumn(""Customers"", ""Foo"");
        }
        
        public override void Down()
        {
        }
    }
}
",
                generatedMigration.UserCode);
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:36,代码来源:CSharpMigrationCodeGeneratorTests.cs


示例12: Generate_can_output_timestamp_column

        public void Generate_can_output_timestamp_column()
        {
            var codeGenerator = new CSharpMigrationCodeGenerator();

            var createTableOperation = new CreateTableOperation("Customers");
            var column = new ColumnModel(PrimitiveTypeKind.Binary)
                             {
                                 Name = "Version",
                                 IsTimestamp = true
                             };
            createTableOperation.Columns.Add(column);

            var generatedMigration
                = codeGenerator.Generate(
                    "Migration",
                    new MigrationOperation[] { createTableOperation },
                    "Source",
                    "Target",
                    "Foo",
                    "Bar");

            Assert.Equal(
                @"namespace Foo
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class Bar : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                ""Customers"",
                c => new
                    {
                        Version = c.Binary(timestamp: true),
                    });
            
        }
        
        public override void Down()
        {
            DropTable(""Customers"");
        }
    }
}
",
                generatedMigration.UserCode);
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:49,代码来源:CSharpMigrationCodeGeneratorTests.cs


示例13: Generate_can_process_null_source_model

        public void Generate_can_process_null_source_model()
        {
            var codeGenerator = new CSharpMigrationCodeGenerator();

            var generatedMigration = codeGenerator.Generate(
                "Migration",
                new MigrationOperation[] { },
                null,
                "Target",
                "Foo",
                "Bar");

            Assert.Equal(
                @"// <auto-generated />
namespace Foo
{
    using System.Data.Entity.Migrations;
    using System.Data.Entity.Migrations.Infrastructure;
    using System.Resources;
    
    public sealed partial class Bar : IMigrationMetadata
    {
        private readonly ResourceManager Resources = new ResourceManager(typeof(Bar));
        
        string IMigrationMetadata.Id
        {
            get { return ""Migration""; }
        }
        
        string IMigrationMetadata.Source
        {
            get { return null; }
        }
        
        string IMigrationMetadata.Target
        {
            get { return Resources.GetString(""Target""); }
        }
    }
}
",
                generatedMigration.DesignerCode);

            Assert.Equal(1, generatedMigration.Resources.Count);
            Assert.Equal("Target", generatedMigration.Resources["Target"]);
        }
开发者ID:junxy,项目名称:entityframework,代码行数:46,代码来源:CSharpMigrationCodeGeneratorTests.cs


示例14: Generate_can_output_composite_add_foreign_key

        public void Generate_can_output_composite_add_foreign_key()
        {
            var codeGenerator = new CSharpMigrationCodeGenerator();

            var addForeignKeyOperation
                = new AddForeignKeyOperation
                      {
                          DependentTable = "Orders",
                          PrincipalTable = "Customers"
                      };

            addForeignKeyOperation.DependentColumns.Add("CustomerId1");
            addForeignKeyOperation.DependentColumns.Add("CustomerId2");
            addForeignKeyOperation.PrincipalColumns.Add("Id1");
            addForeignKeyOperation.PrincipalColumns.Add("Id2");

            var generatedMigration
                = codeGenerator.Generate(
                    "Migration",
                    new MigrationOperation[] { addForeignKeyOperation },
                    "Source",
                    "Target",
                    "Foo",
                    "Bar");

            Assert.Equal(
                @"namespace Foo
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class Bar : DbMigration
    {
        public override void Up()
        {
            AddForeignKey(""Orders"", new[] { ""CustomerId1"", ""CustomerId2"" }, ""Customers"", new[] { ""Id1"", ""Id2"" });
        }
        
        public override void Down()
        {
            DropForeignKey(""Orders"", new[] { ""CustomerId1"", ""CustomerId2"" }, ""Customers"");
        }
    }
}
",
                generatedMigration.UserCode);
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:47,代码来源:CSharpMigrationCodeGeneratorTests.cs


示例15: Generate_should_scrub_class_name

        public void Generate_should_scrub_class_name()
        {
            var codeGenerator = new CSharpMigrationCodeGenerator();

            var generatedMigration = codeGenerator.Generate(
                "Migration",
                new MigrationOperation[] { },
                "Source",
                "Target",
                "Foo",
                "1$%^&DFDSH");

            Assert.True(generatedMigration.UserCode.Contains("class _1DFDSH"));

            generatedMigration = codeGenerator.Generate(
                "Migration",
                new MigrationOperation[] { },
                "Source",
                "Target",
                "Foo",
                "while");

            Assert.True(generatedMigration.UserCode.Contains("class _while"));
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:24,代码来源:CSharpMigrationCodeGeneratorTests.cs


示例16: Generate_create_fully_configured_create_index_operation

        public void Generate_create_fully_configured_create_index_operation()
        {
            var createIndexOperation = new CreateIndexOperation
            {
                Table = "MyTable",
                Name = "MyIndex",
                IsClustered = true,
                IsUnique = true
            };
            createIndexOperation.Columns.Add("MyColumn");

            var generatedMigration
                = new CSharpMigrationCodeGenerator().Generate(
                    "Migration",
                    new MigrationOperation[]
                        {
                            createIndexOperation
                        },
                    "Source",
                    "Target",
                    "Foo",
                    "Bar");

            Assert.Equal(
                @"namespace Foo
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class Bar : DbMigration
    {
        public override void Up()
        {
            CreateIndex(""MyTable"", ""MyColumn"", unique: true, clustered: true, name: ""MyIndex"");
        }
        
        public override void Down()
        {
            DropIndex(""MyTable"", ""MyIndex"");
        }
    }
}
",
                generatedMigration.UserCode);
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:45,代码来源:CSharpMigrationCodeGeneratorTests.cs


示例17: Can_generate_AlterTableAnnotations_with_annotations

        public void Can_generate_AlterTableAnnotations_with_annotations()
        {
            var operation = new AlterTableOperation(
                "Customers",
                new Dictionary<string, AnnotationValues>
                {
                    { "AT1", new AnnotationValues(null, "VT1") },
                    {
                        CollationAttribute.AnnotationName,
                        new AnnotationValues(
                            new CollationAttribute("At a reasonable volume..."),
                            new CollationAttribute("While I'm collating..."))
                    },
                    { "AT2", new AnnotationValues(null, "VT2") }

                });

            var idColumn = new ColumnModel(PrimitiveTypeKind.Int32)
            {
                Name = "I.d",
                IsNullable = true,
                IsIdentity = true,
                Annotations =
                    new Dictionary<string, AnnotationValues>
                    {
                        { "A1", new AnnotationValues(null, "V1") },
                        { "A2", new AnnotationValues(null, "V2") }
                    }
            };
            operation.Columns.Add(idColumn);

            operation.Columns.Add(
                new ColumnModel(PrimitiveTypeKind.String)
                {
                    Name = "Name",
                    IsNullable = false,
                    Annotations =
                        new Dictionary<string, AnnotationValues>
                        {
                            {
                                CollationAttribute.AnnotationName,
                                new AnnotationValues(
                                    new CollationAttribute("At a reasonable volume..."),
                                    new CollationAttribute("While I'm collating..."))
                            }
                        }
                });

            var operations = new[] { operation };

            var generator = new CSharpMigrationCodeGenerator();
            generator.AnnotationGenerators[CollationAttribute.AnnotationName] = () => new CollationCSharpCodeGenerator();
            var generatedMigration = generator.Generate("Migration", operations, "Source", "Target", "MyNamespace", "MyMigration");

            Assert.Equal(
                @"namespace MyNamespace
{
    using System;
    using System.Collections.Generic;
    using System.Data.Entity.Infrastructure.Annotations;
    using System.Data.Entity.Migrations;
    using System.Data.Entity.TestHelpers;
    
    public partial class MyMigration : DbMigration
    {
        public override void Up()
        {
            AlterTableAnnotations(
                ""Customers"",
                c => new
                    {
                        Id = c.Int(name: ""I.d"", identity: true,
                            annotations: new Dictionary<string, AnnotationValues>
                            {
                                { 
                                    ""A1"",
                                    new AnnotationValues(oldValue: null, newValue: ""V1"")
                                },
                                { 
                                    ""A2"",
                                    new AnnotationValues(oldValue: null, newValue: ""V2"")
                                },
                            }),
                        Name = c.String(nullable: false,
                            annotations: new Dictionary<string, AnnotationValues>
                            {
                                { 
                                    ""Collation"",
                                    new AnnotationValues(oldValue: new CollationAttribute(""At a reasonable volume...""), newValue: new CollationAttribute(""While I'm collating...""))
                                },
                            }),
                    },
                annotations: new Dictionary<string, AnnotationValues>
                {
                    { 
                        ""AT1"",
                        new AnnotationValues(oldValue: null, newValue: ""VT1"")
                    },
                    { 
                        ""AT2"",
//.........这里部分代码省略.........
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:101,代码来源:CSharpMigrationCodeGeneratorTests.cs


示例18: MigrationIds_should_not_return_migration_in_wrong_namespace

        public void MigrationIds_should_not_return_migration_in_wrong_namespace()
        {
            var codeGenerator = new CSharpMigrationCodeGenerator();

            var @namespace = "CorrectNamespace";

            var generatedMigration
                = codeGenerator.Generate(
                    "201108162311111_Migration",
                    new MigrationOperation[] { },
                    "Source",
                    "Target",
                    @namespace,
                    "Migration");

            var migrationAssembly = new MigrationAssembly(
                new MigrationCompiler("cs").Compile(@namespace, generatedMigration),
                "WrongNamespace");

            Assert.Equal(0, migrationAssembly.MigrationIds.Count());
        }
开发者ID:christiandpena,项目名称:entityframework,代码行数:21,代码来源:MigrationAssemblyTests.cs


示例19: Can_generate_AddColumn_with_custom_annotation_code_gen

        public void Can_generate_AddColumn_with_custom_annotation_code_gen()
        {
            var operations = new[]
            {
                new AddColumnOperation(
                    "MyTable",
                    new ColumnModel(PrimitiveTypeKind.String)
                    {
                        Name = "MyColumn",
                        IsFixedLength = true,
                        Annotations =
                            new Dictionary<string, AnnotationValues>
                            {
                                {
                                    CollationAttribute.AnnotationName,
                                    new AnnotationValues(
                                        new CollationAttribute("At a reasonable volume..."),
                                        new CollationAttribute("While I'm collating..."))
                                }
                            }
                    },
                    false),
            };

            var generator = new CSharpMigrationCodeGenerator();
            generator.AnnotationGenerators[CollationAttribute.AnnotationName] = () => new CollationCSharpCodeGenerator();
            var generatedMigration = generator.Generate("Migration", operations, "Source", "Target", "MyNamespace", "MyMigration");

            Assert.Equal(
                @"namespace MyNamespace
{
    using System;
    using System.Collections.Generic;
    using System.Data.Entity.Infrastructure.Annotations;
    using System.Data.Entity.Migrations;
    using System.Data.Entity.TestHelpers;
    
    public partial class MyMigration : DbMigration
    {
        public override void Up()
        {
            AddColumn(""MyTable"", ""MyColumn"", c => c.String(fixedLength: true,
                annotations: new Dictionary<string, AnnotationValues>
                {
                    { 
                        ""Collation"",
                        new AnnotationValues(oldValue: new CollationAttribute(""At a reasonable volume...""), newValue: new CollationAttribute(""While I'm collating...""))
                    },
                }));
        }
        
        public override void Down()
        {
            DropColumn(""MyTable"", ""MyColumn"",
                removedAnnotations: new Dictionary<string, object>
                {
                    { ""Collation"", new CollationAttribute(""While I'm collating..."") },
                });
        }
    }
}
",
                generatedMigration.UserCode);
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:64,代码来源:CSharpMigrationCodeGeneratorTests.cs


示例20: Can_generate_AddColumn_with_annotations

        public void Can_generate_AddColumn_with_annotations()
        {
            var operations = new[]
            {
                new AddColumnOperation(
                    "MyTable",
                    new ColumnModel(PrimitiveTypeKind.String)
                    {
                        Name = "MyColumn",
                        IsFixedLength = true,
                        Annotations =
                            new Dictionary<string, AnnotationValues>
                            {
                                { "A3", new AnnotationValues(null, "V3") },
                                { "A1", new AnnotationValues(null, "V1") },
                            }
                    },
                    false),
            };

            var generator = new CSharpMigrationCodeGenerator();
            var generatedMigration = generator.Generate("Migration", operations, "Source", "Target", "MyNamespace", "MyMigration");

            Assert.Equal(
                @"namespace MyNamespace
{
    using System;
    using System.Collections.Generic;
    using System.Data.Entity.Infrastructure.Annotations;
    using System.Data.Entity.Migrations;
    
    public partial class MyMigration : DbMigration
    {
        public override void Up()
        {
            AddColumn(""MyTable"", ""MyColumn"", c => c.String(fixedLength: true,
                annotations: new Dictionary<string, AnnotationValues>
                {
                    { 
                        ""A1"",
                        new AnnotationValues(oldValue: null, newValue: ""V1"")
                    },
                    { 
                        ""A3"",
                        new AnnotationValues(oldValue: null, newValue: ""V3"")
             

鲜花

握手

雷人

路过

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

请发表评论

全部评论

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