@@ -3256,6 +3256,118 @@ public virtual Task Add_required_primitve_collection_with_custom_converter_and_c
3256
3256
Assert . Single ( customersTable . PrimaryKey ! . Columns ) ) ;
3257
3257
} ) ;
3258
3258
3259
+ [ ConditionalFact ]
3260
+ public virtual Task Multiop_drop_table_and_create_the_same_table_in_one_migration ( )
3261
+ => TestComposite (
3262
+ [
3263
+ builder => builder . Entity (
3264
+ "Customer" , e =>
3265
+ {
3266
+ e . Property < int > ( "Id" ) . ValueGeneratedOnAdd ( ) ;
3267
+ e . Property < string > ( "Name" ) ;
3268
+ e . HasKey ( "Id" ) ;
3269
+ e . ToTable ( "Customers" ) ;
3270
+ } ) ,
3271
+ builder => { } ,
3272
+ builder => builder . Entity (
3273
+ "Customer" , e =>
3274
+ {
3275
+ e . Property < int > ( "Id" ) . ValueGeneratedOnAdd ( ) ;
3276
+ e . Property < string > ( "Name" ) ;
3277
+ e . HasKey ( "Id" ) ;
3278
+
3279
+ e . ToTable ( "Customers" ) ;
3280
+ } )
3281
+ ] ) ;
3282
+
3283
+ [ ConditionalFact ]
3284
+ public virtual Task Multiop_create_table_and_drop_it_in_one_migration ( )
3285
+ => TestComposite (
3286
+ [
3287
+ builder => { } ,
3288
+ builder => builder . Entity (
3289
+ "Customer" , e =>
3290
+ {
3291
+ e . Property < int > ( "Id" ) . ValueGeneratedOnAdd ( ) ;
3292
+ e . Property < string > ( "Name" ) ;
3293
+ e . HasKey ( "Id" ) ;
3294
+
3295
+ e . ToTable ( "Customers" ) ;
3296
+ } ) ,
3297
+ builder => { } ,
3298
+ ] ) ;
3299
+
3300
+ [ ConditionalFact ]
3301
+ public virtual Task Multiop_rename_table_and_drop ( )
3302
+ => TestComposite (
3303
+ [
3304
+ builder => builder . Entity (
3305
+ "Customer" , e =>
3306
+ {
3307
+ e . Property < int > ( "Id" ) . ValueGeneratedOnAdd ( ) ;
3308
+ e . Property < string > ( "Name" ) ;
3309
+ e . HasKey ( "Id" ) ;
3310
+
3311
+ e . ToTable ( "Customers" ) ;
3312
+ } ) ,
3313
+ builder => builder . Entity (
3314
+ "Customer" , e =>
3315
+ {
3316
+ e . Property < int > ( "Id" ) . ValueGeneratedOnAdd ( ) ;
3317
+ e . Property < string > ( "Name" ) ;
3318
+ e . HasKey ( "Id" ) ;
3319
+
3320
+ e . ToTable ( "NewCustomers" ) ;
3321
+ } ) ,
3322
+ builder => { } ,
3323
+ ] ) ;
3324
+
3325
+ [ ConditionalFact ]
3326
+ public virtual Task Multiop_rename_table_and_create_new_table_with_the_old_name ( )
3327
+ => TestComposite (
3328
+ [
3329
+ builder => builder . Entity (
3330
+ "Customer" , e =>
3331
+ {
3332
+ e . Property < int > ( "Id" ) . ValueGeneratedOnAdd ( ) ;
3333
+ e . Property < string > ( "Name" ) ;
3334
+ e . HasKey ( "Id" ) ;
3335
+
3336
+ e . ToTable ( "Customers" ) ;
3337
+ } ) ,
3338
+ builder => builder . Entity (
3339
+ "Customer" , e =>
3340
+ {
3341
+ e . Property < int > ( "Id" ) . ValueGeneratedOnAdd ( ) ;
3342
+ e . Property < string > ( "Name" ) ;
3343
+ e . HasKey ( "Id" ) ;
3344
+
3345
+ e . ToTable ( "NewCustomers" ) ;
3346
+ } ) ,
3347
+ builder =>
3348
+ {
3349
+ builder . Entity (
3350
+ "Customer" , e =>
3351
+ {
3352
+ e . Property < int > ( "Id" ) . ValueGeneratedOnAdd ( ) ;
3353
+ e . Property < string > ( "Name" ) ;
3354
+ e . HasKey ( "Id" ) ;
3355
+
3356
+ e . ToTable ( "NewCustomers" ) ;
3357
+ } ) ;
3358
+
3359
+ builder . Entity (
3360
+ "AnotherCustomer" , e =>
3361
+ {
3362
+ e . Property < int > ( "Id" ) . ValueGeneratedOnAdd ( ) ;
3363
+ e . Property < string > ( "Name" ) ;
3364
+ e . HasKey ( "Id" ) ;
3365
+
3366
+ e . ToTable ( "Customers" ) ;
3367
+ } ) ;
3368
+ } ,
3369
+ ] ) ;
3370
+
3259
3371
protected class Person
3260
3372
{
3261
3373
public int Id { get ; set ; }
@@ -3305,6 +3417,43 @@ protected virtual Task Test(
3305
3417
MigrationsSqlGenerationOptions migrationsSqlGenerationOptions = MigrationsSqlGenerationOptions . Default )
3306
3418
=> Test ( _ => { } , buildSourceAction , buildTargetAction , asserter , withConventions , migrationsSqlGenerationOptions ) ;
3307
3419
3420
+ protected virtual Task TestComposite (
3421
+ List < Action < ModelBuilder > > buildActions ,
3422
+ bool withConventions = true ,
3423
+ MigrationsSqlGenerationOptions migrationsSqlGenerationOptions = MigrationsSqlGenerationOptions . Default )
3424
+ {
3425
+ if ( buildActions . Count < 3 )
3426
+ {
3427
+ throw new InvalidOperationException ( "You need at least 3 build actions for the composite case." ) ;
3428
+ }
3429
+
3430
+ var context = CreateContext ( ) ;
3431
+ var modelDiffer = context . GetService < IMigrationsModelDiffer > ( ) ;
3432
+ var modelRuntimeInitializer = context . GetService < IModelRuntimeInitializer > ( ) ;
3433
+
3434
+ var models = new List < IModel > ( ) ;
3435
+ for ( var i = 0 ; i < buildActions . Count ; i ++ )
3436
+ {
3437
+ var modelBuilder = CreateModelBuilder ( withConventions ) ;
3438
+ buildActions [ i ] ( modelBuilder ) ;
3439
+
3440
+ var preSnapshotModel = modelRuntimeInitializer . Initialize (
3441
+ ( IModel ) modelBuilder . Model , designTime : true , validationLogger : null ) ;
3442
+
3443
+ models . Add ( preSnapshotModel ) ;
3444
+ }
3445
+
3446
+ // build all migration operations going through each intermediate state of the model
3447
+ var operations = new List < MigrationOperation > ( ) ;
3448
+ for ( var i = 0 ; i < models . Count - 1 ; i ++ )
3449
+ {
3450
+ operations . AddRange (
3451
+ modelDiffer . GetDifferences ( models [ i ] . GetRelationalModel ( ) , models [ i + 1 ] . GetRelationalModel ( ) ) ) ;
3452
+ }
3453
+
3454
+ return Test ( models . First ( ) , models . Last ( ) , operations , null , migrationsSqlGenerationOptions ) ;
3455
+ }
3456
+
3308
3457
protected virtual Task Test (
3309
3458
Action < ModelBuilder > buildCommonAction ,
3310
3459
Action < ModelBuilder > buildSourceAction ,
0 commit comments