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


C# Design.MigrationScaffolder类代码示例

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


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

示例1: Upgrade_from_earlier_version_should_upgrade_history_table_when_updating_generated

        public void Upgrade_from_earlier_version_should_upgrade_history_table_when_updating_generated()
        {
            ResetDatabase();

            var createTableOperation = GetLegacyHistoryCreateTableOperation();

            createTableOperation.Columns.Remove(createTableOperation.Columns.Last());
            createTableOperation.Columns.Add(new ColumnModel(PrimitiveTypeKind.String) { Name = "Hash" });

            ExecuteOperations(
                createTableOperation,
                new SqlOperation(
                    "INSERT INTO [__MigrationHistory] ([MigrationId], [CreatedOn], [Model]) VALUES ('000000000000000_ExistingMigration', GETDATE(), 0x1F8B0800000000000400ECBD07601C499625262F6DCA7B7F4AF54AD7E074A10880601324D8904010ECC188CDE692EC1D69472329AB2A81CA6556655D661640CCED9DBCF7DE7BEFBDF7DE7BEFBDF7BA3B9D4E27F7DFFF3F5C6664016CF6CE4ADAC99E2180AAC81F3F7E7C1F3F22FEC7BFF71F7CFC7BBC5B94E9655E3745B5FCECA3DDF1CE4769BE9C56B36279F1D947EBF67CFBE0A3DFE3E8374E1E9FCE16EFD29F34EDF6D08EDE5C369F7D346FDBD5A3BB779BE93C5F64CD78514CEBAAA9CEDBF1B45ADCCD66D5DDBD9D9D83BBBB3B777302F111C14AD3C7AFD6CBB658E4FC07FD79522DA7F9AA5D67E517D52C2F1BFD9CBE79CD50D317D9226F56D934FFEC236ADB54657EBC5A95C5346B099DDD8FD2E3B2C80895D77979FE9E78ED3C045E1FD91EA9CF53C2ADBDA67EDAAC58E63577CEFDB6F9BBF6A3F4AEC3EEAEA067867177601C8FBFC8562B22A8372EFD247DAD83DA7EFDFE782F04C6DD69B3097DDB535BD5D945DEF916E39AE5CF8ABA699F666D36C99AFCA3F464B688348B0C5F61DBF177C6F958FBBCCDA4769090261FA52FEBEAB2980181D7D74D9B2FC668307EFD8BCA93B2C897AD6BF045B62CCEF3A67D53BDCDC1A044A3AFCF160FEFEEEC812DEE36CDACBC156FF468B8814BFA54797CD71788C74FF3A6B820E89E782CF32958DD01356DCE96E715D16095D7EDF5EBBCF571354DCCD78AEC17799BCD08CFE3BA2DCEB3694B5F4FF3A6A179FB28FDC9AC5C5393D3C5249F9D2DBF5CB7AB757BDC34F962525E8763DADC3F8B4288F3E32F57F8CB6383AF3F0442B3A021E45F2E9FAC8B7266F17E969521ED874160CA3ECFE9735621AF5BFA995F5C5B482FAAE52D0129F99EE6AB7C3923967C932F5625016BBE5CBECE2EF361DC6EA66148B1C74F8BECA2CE163E05E513C5E475463D7B5D5007FE1BAE3FFAF3F15D28F4A3FF270000FFFF4817137F02060000)"));

            var migrator = CreateMigrator<ShopContext_v1>();

            var generatedMigration = new MigrationScaffolder(migrator.Configuration).Scaffold("Migration1");

            migrator = CreateMigrator<ShopContext_v1>(
                automaticMigrationsEnabled: false,
                scaffoldedMigrations: new[] { generatedMigration });

            Assert.False(ColumnExists(HistoryContext.TableName, "ProductVersion"));
            Assert.True(ColumnExists(HistoryContext.TableName, "Hash"));
            Assert.True(ColumnExists(HistoryContext.TableName, "CreatedOn"));

            migrator.Update(generatedMigration.MigrationId);

            Assert.True(ColumnExists(HistoryContext.TableName, "ProductVersion"));
            Assert.False(ColumnExists(HistoryContext.TableName, "Hash"));
            Assert.False(ColumnExists(HistoryContext.TableName, "CreatedOn"));
        }
开发者ID:jimmy00784,项目名称:entityframework,代码行数:32,代码来源:DbMigratorTests.cs

示例2: Add

		public void Add (string title)
		{
			
			var scaffolder = new MigrationScaffolder (_config);

			var migration = scaffolder.Scaffold (title);

			//Because monodevelop/xamarin doesn't support resxfilecodegenerator, we can't user resx files properly
			//Another issue is lack of power shell support which force us to generate all cs/resx files manually and add them to 
			//projet, what is why we are going to put all migration data to one file using ugly hacks
			//Code might stop working on future versions of Entity framework.

			//Add Migration Namespace
			migration.UserCode = "using System.Data.Entity.Migrations.Infrastructure;\n\n" + migration.UserCode;

			//Add IMigrationMetadata interface
			migration.UserCode = migration.UserCode.Replace ("DbMigration", "DbMigration, IMigrationMetadata");

			//Insert IMigrationMetadate implementation
			migration.UserCode = migration.UserCode.Replace ("public override void Up()",
				string.Format ("\tstring IMigrationMetadata.Id {{\n\t\t\t" +
				"get {{ return \"{0}\"; }}\n\t\t" +
				"}}\n\n\t\t" +
				"string IMigrationMetadata.Source {{\n\t\t\t" +
				"get {{ return null; }}\n\t\t" +
				"}}\n\n\n\t\t" +
				"string IMigrationMetadata.Target {{\n\t\t\t" +
				"get {{ return \"{1}\"; }}\n\t\t}}" +
				"\n\n\tpublic override void Up()", migration.MigrationId, migration.Resources ["Target"]));

			File.WriteAllText (Path.Combine (_migrationFolder, migration.MigrationId + ".cs"), migration.UserCode);
		}
开发者ID:jamespack,项目名称:DemiByte.EntityFrameworkMigrationSample,代码行数:32,代码来源:MigrationManager.cs

示例3: Can_scaffold_on_sql_and_run_on_ce_after_initial_auto

        public void Can_scaffold_on_sql_and_run_on_ce_after_initial_auto()
        {
            DatabaseProvider = DatabaseProvider.SqlClient;

            ResetDatabase();

            var migrator = CreateMigrator<CrossProviderContext_v1>();

            migrator.Update();

            migrator = CreateMigrator<CrossProviderContext_v2>();

            var scaffoldedMigration = new MigrationScaffolder(migrator.Configuration).Scaffold("Migration");

            DatabaseProvider = DatabaseProvider.SqlServerCe;

            ResetDatabase();

            migrator = CreateMigrator<CrossProviderContext_v2>(scaffoldedMigrations: scaffoldedMigration);

            migrator.Update();

            Assert.True(TableExists("MigrationsProducts"));
            Assert.False(ColumnExists("MigrationsProducts", "CustomerNumber"));
        }
开发者ID:WangWilliam,项目名称:EntityFramework5,代码行数:25,代码来源:CrossDatabaseScenarios.cs

示例4: Can_explicit_update_when_custom_history_factory

        public void Can_explicit_update_when_custom_history_factory()
        {
            ResetDatabase();

            var migrator
                = CreateMigrator<ShopContext_v1>(historyContextFactory: _testHistoryContextFactoryA);

            var generatedMigration
                = new MigrationScaffolder(migrator.Configuration).Scaffold("Migration");

            migrator
                = CreateMigrator<ShopContext_v1>(
                    automaticMigrationsEnabled: false,
                    scaffoldedMigrations: generatedMigration,
                    historyContextFactory: _testHistoryContextFactoryA);

            migrator.Update();

            Assert.True(TableExists("MigrationsCustomers"));
            Assert.True(TableExists("__Migrations"));

            migrator.Update("0");

            Assert.False(TableExists("MigrationsCustomers"));
            Assert.False(TableExists("__Migrations"));

            var historyRepository = new HistoryRepository(ConnectionString, ProviderFactory, "MyKey", null);

            Assert.Null(historyRepository.GetLastModel());
        }
开发者ID:christiandpena,项目名称:entityframework,代码行数:30,代码来源:CustomHistoryScenarios.cs

示例5: Generate_when_empty_source_database_should_diff_against_empty_model

        public void Generate_when_empty_source_database_should_diff_against_empty_model()
        {
            ResetDatabase();

            var migrator = CreateMigrator<ShopContext_v1>();

            var generatedMigration = new MigrationScaffolder(migrator.Configuration).Scaffold("Migration");

            Assert.Equal(4, Regex.Matches(generatedMigration.UserCode, "CreateTable").Count);
        }
开发者ID:jimmy00784,项目名称:entityframework,代码行数:10,代码来源:BasicMigrationScenarios.cs

示例6: Can_generate_against_existing_model

        public void Can_generate_against_existing_model()
        {
            Can_generate_and_update_against_empty_source_model();

            var migrator = CreateMigrator<ShopContext_v2>();

            var generatedMigration = new MigrationScaffolder(migrator.Configuration).Scaffold("Migration_v2");

            Assert.Equal(2, Regex.Matches(generatedMigration.UserCode, "RenameTable").Count);
        }
开发者ID:jimmy00784,项目名称:entityframework,代码行数:10,代码来源:BasicMigrationScenarios.cs

示例7: Generate_should_create_custom_migration_step

        public void Generate_should_create_custom_migration_step()
        {
            ResetDatabase();

            var migrator = CreateMigrator<ShopContext_v1>();

            var generatedMigration = new MigrationScaffolder(migrator.Configuration).Scaffold("Migration");

            Assert.NotNull(generatedMigration);
            Assert.True(generatedMigration.MigrationId.Contains("Migration"));
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:11,代码来源:BasicMigrationScenarios.cs

示例8: Scaffold_throws_when_pending_migrations

        public void Scaffold_throws_when_pending_migrations()
        {
            var migrator = CreateMigrator<ShopContext_v1>();
            var migration = new MigrationScaffolder(migrator.Configuration).Scaffold("M1");

            Assert.Equal(
                Strings.MigrationsPendingException(migration.MigrationId),
                Assert.Throws<MigrationsPendingException>(
                    () => CreateMigrator<ShopContext_v1>(
                        scaffoldedMigrations: new[] { migration })
                              .Scaffold("M2", "N", false)).Message);
        }
开发者ID:christiandpena,项目名称:entityframework,代码行数:12,代码来源:DbMigratorTests.cs

示例9: Can_script_windows

        public void Can_script_windows(bool whenDatabaseExists)
        {
            ResetDatabase();

            var migrator1 = CreateMigrator<ShopContext_v1>();
            var version1 = new MigrationScaffolder(migrator1.Configuration).Scaffold("Version1");

            CreateMigrator<ShopContext_v1>(scaffoldedMigrations: version1).Update();

            var migrator2 = CreateMigrator<ShopContext_v2>(scaffoldedMigrations: version1);

            var version2 = new MigrationScaffolder(migrator2.Configuration).Scaffold("Version2");

            CreateMigrator<ShopContext_v2>(scaffoldedMigrations: new[] { version1, version2 }).Update();

            var migrator3 = CreateMigrator<ShopContext_v3>(scaffoldedMigrations: new[] { version1, version2 });
            var version3 = new MigrationScaffolder(migrator3.Configuration).Scaffold("Version3");

            var migrator4 = CreateMigrator<ShopContext_v3>(scaffoldedMigrations: new[] { version1, version2, version3 });
            var scriptingDecorator = new MigratorScriptingDecorator(migrator4);

            if (!whenDatabaseExists)
            {
                ResetDatabase();
            }

            // All
            var script = scriptingDecorator.ScriptUpdate(DbMigrator.InitialDatabase, null);

            Assert.True(script.Contains(CreateMetadataStatement));
            Assert.True(script.Contains("Version1"));
            Assert.True(script.Contains("Version2"));
            Assert.True(script.Contains("Version3"));
            Assert.False(script.Contains("AutomaticMigration"));

            // 1
            script = scriptingDecorator.ScriptUpdate(DbMigrator.InitialDatabase, version1.MigrationId);

            Assert.True(script.Contains(CreateMetadataStatement));
            Assert.True(script.Contains("Version1"));
            Assert.False(script.Contains("Version2"));
            Assert.False(script.Contains("Version3"));
            Assert.False(script.Contains("AutomaticMigration"));

            // 1 & 2
            script = scriptingDecorator.ScriptUpdate(DbMigrator.InitialDatabase, version2.MigrationId);

            Assert.True(script.Contains(CreateMetadataStatement));
            Assert.True(script.Contains("Version1"));
            Assert.True(script.Contains("Version2"));
            Assert.False(script.Contains("Version3"));
            Assert.False(script.Contains("AutomaticMigration"));
        }
开发者ID:WangWilliam,项目名称:EntityFramework5,代码行数:53,代码来源:DashScriptScenarios.cs

示例10: Can_generate_migration_with_store_side_renames

        public void Can_generate_migration_with_store_side_renames()
        {
            ResetDatabase();

            CreateMigrator<ShopContext_v1>().Update();

            var migrator = CreateMigrator<ShopContext_v2>();

            var generatedMigration = new MigrationScaffolder(migrator.Configuration).Scaffold("Migration");

            Assert.True(generatedMigration.UserCode.Contains("RenameTable"));
            WhenNotSqlCe(() => Assert.True(generatedMigration.UserCode.Contains("RenameColumn")));
        }
开发者ID:jimmy00784,项目名称:entityframework,代码行数:13,代码来源:BasicMigrationScenarios.cs

示例11: Can_generate_and_update_against_empty_source_model

        public void Can_generate_and_update_against_empty_source_model()
        {
            ResetDatabase();

            var migrator = CreateMigrator<ShopContext_v1>();

            var generatedMigration = new MigrationScaffolder(migrator.Configuration).Scaffold("Migration_v1");

            migrator = CreateMigrator<ShopContext_v1>(false, scaffoldedMigrations: generatedMigration);

            migrator.Update();

            Assert.True(TableExists("MigrationsProducts"));
        }
开发者ID:jimmy00784,项目名称:entityframework,代码行数:14,代码来源:BasicMigrationScenarios.cs

示例12: GetMigrations_should_return_migrations_list

        public void GetMigrations_should_return_migrations_list()
        {
            var migrator = CreateMigrator<ShopContext_v1>();

            Assert.True(!migrator.GetLocalMigrations().Any());

            var generatedMigration = new MigrationScaffolder(migrator.Configuration).Scaffold("Migration");

            migrator = CreateMigrator<ShopContext_v1>(
                automaticMigrationsEnabled: false,
                scaffoldedMigrations: generatedMigration);

            Assert.Equal(1, migrator.GetLocalMigrations().Count());
        }
开发者ID:christiandpena,项目名称:entityframework,代码行数:14,代码来源:DbMigratorTests.cs

示例13: Can_generate_and_update_when_custom_default_schema

        public void Can_generate_and_update_when_custom_default_schema()
        {
            DropDatabase();

            var migrator = CreateMigrator<CustomSchemaContext2>();

            var generatedMigration = new MigrationScaffolder(migrator.Configuration).Scaffold("Migration_v1");

            migrator = CreateMigrator<CustomSchemaContext2>(false, scaffoldedMigrations: generatedMigration);

            migrator.Update();

            Assert.True(TableExists("bar.OrderLines"));
            Assert.True(TableExists("ordering.Orders"));
            Assert.True(TableExists("bar." + HistoryContext.TableName));
        }
开发者ID:WangWilliam,项目名称:EntityFramework5,代码行数:16,代码来源:SchemaScenarios.cs

示例14: Can_update_generate_update_when_empty_target_database

        public void Can_update_generate_update_when_empty_target_database()
        {
            ResetDatabase();

            CreateMigrator<ShopContext_v1>().Update();

            Assert.True(TableExists("MigrationsProducts"));

            var migrator = CreateMigrator<ShopContext_v2>();

            var generatedMigration = new MigrationScaffolder(migrator.Configuration).Scaffold("Migration");

            migrator = CreateMigrator<ShopContext_v2>(false, scaffoldedMigrations: generatedMigration);

            migrator.Update();

            Assert.True(TableExists("crm.tbl_customers"));
        }
开发者ID:jimmy00784,项目名称:entityframework,代码行数:18,代码来源:BasicMigrationScenarios.cs

示例15: Auto_migration_when_functions_and_model_not_current_should_throw

        public void Auto_migration_when_functions_and_model_not_current_should_throw()
        {
            ResetDatabase();

            var migrator = CreateMigrator<ShopContext_v1>();

            migrator.Update();

            migrator = CreateMigrator<ShopContext_v2>();

            var generatedMigration = new MigrationScaffolder(migrator.Configuration).Scaffold("Migration");

            migrator = CreateMigrator<ShopContext_v2>(scaffoldedMigrations: generatedMigration);

            ResetDatabase();

            Assert.Throws<MigrationsException>(() => migrator.Update())
                  .ValidateMessage("AutomaticStaleFunctions");
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:19,代码来源:ModificationFunctionsScenarios.cs


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