@@ -2288,6 +2288,122 @@ PERIOD FOR SYSTEM_TIME([SystemTimeStart], [SystemTimeEnd])
2288
2288
) WITH (SYSTEM_VERSIONING = ON (HISTORY_TABLE = [mySchema].[CustomersHistory]));" ) ;
2289
2289
}
2290
2290
2291
+ [ ConditionalFact ]
2292
+ public virtual async Task Create_temporal_table_with_default_schema_for_model_changed_and_explicit_history_table_schema_not_provided ( )
2293
+ {
2294
+ await Test (
2295
+ builder => { } ,
2296
+ builder =>
2297
+ {
2298
+ builder . HasDefaultSchema ( "myDefaultSchema" ) ;
2299
+ builder . Entity (
2300
+ "Customer" , e =>
2301
+ {
2302
+ e . Property < int > ( "Id" ) . ValueGeneratedOnAdd ( ) ;
2303
+ e . Property < string > ( "Name" ) ;
2304
+ e . Property < DateTime > ( "SystemTimeStart" ) . ValueGeneratedOnAddOrUpdate ( ) ;
2305
+ e . Property < DateTime > ( "SystemTimeEnd" ) . ValueGeneratedOnAddOrUpdate ( ) ;
2306
+ e . HasKey ( "Id" ) ;
2307
+
2308
+ e . ToTable ( "Customers" , tb => tb . IsTemporal ( ttb =>
2309
+ {
2310
+ ttb . UseHistoryTable ( "HistoryTable" ) ;
2311
+ ttb . HasPeriodStart ( "SystemTimeStart" ) ;
2312
+ ttb . HasPeriodEnd ( "SystemTimeEnd" ) ;
2313
+ } ) ) ;
2314
+ } ) ;
2315
+ } ,
2316
+ model =>
2317
+ {
2318
+ var table = Assert . Single ( model . Tables ) ;
2319
+ Assert . Equal ( "Customers" , table . Name ) ;
2320
+ Assert . Equal ( true , table [ SqlServerAnnotationNames . IsTemporal ] ) ;
2321
+ Assert . Equal ( "HistoryTable" , table [ SqlServerAnnotationNames . TemporalHistoryTableName ] ) ;
2322
+ Assert . Equal ( "myDefaultSchema" , table [ SqlServerAnnotationNames . TemporalHistoryTableSchema ] ) ;
2323
+ Assert . Equal ( "SystemTimeStart" , table [ SqlServerAnnotationNames . TemporalPeriodStartPropertyName ] ) ;
2324
+ Assert . Equal ( "SystemTimeEnd" , table [ SqlServerAnnotationNames . TemporalPeriodEndPropertyName ] ) ;
2325
+
2326
+ Assert . Collection (
2327
+ table . Columns ,
2328
+ c => Assert . Equal ( "Id" , c . Name ) ,
2329
+ c => Assert . Equal ( "Name" , c . Name ) ) ;
2330
+ Assert . Same (
2331
+ table . Columns . Single ( c => c . Name == "Id" ) ,
2332
+ Assert . Single ( table . PrimaryKey ! . Columns ) ) ;
2333
+ } ) ;
2334
+
2335
+ AssertSql (
2336
+ @"IF SCHEMA_ID(N'myDefaultSchema') IS NULL EXEC(N'CREATE SCHEMA [myDefaultSchema];');" ,
2337
+ //
2338
+ @"CREATE TABLE [myDefaultSchema].[Customers] (
2339
+ [Id] int NOT NULL,
2340
+ [Name] nvarchar(max) NULL,
2341
+ [SystemTimeEnd] datetime2 GENERATED ALWAYS AS ROW END HIDDEN NOT NULL,
2342
+ [SystemTimeStart] datetime2 GENERATED ALWAYS AS ROW START HIDDEN NOT NULL,
2343
+ CONSTRAINT [PK_Customers] PRIMARY KEY ([Id]),
2344
+ PERIOD FOR SYSTEM_TIME([SystemTimeStart], [SystemTimeEnd])
2345
+ ) WITH (SYSTEM_VERSIONING = ON (HISTORY_TABLE = [myDefaultSchema].[HistoryTable]));" ) ;
2346
+ }
2347
+
2348
+ [ ConditionalFact ]
2349
+ public virtual async Task Create_temporal_table_with_default_schema_for_model_changed_and_explicit_history_table_schema_provided ( )
2350
+ {
2351
+ await Test (
2352
+ builder => { } ,
2353
+ builder =>
2354
+ {
2355
+ builder . HasDefaultSchema ( "myDefaultSchema" ) ;
2356
+ builder . Entity (
2357
+ "Customer" , e =>
2358
+ {
2359
+ e . Property < int > ( "Id" ) . ValueGeneratedOnAdd ( ) ;
2360
+ e . Property < string > ( "Name" ) ;
2361
+ e . Property < DateTime > ( "SystemTimeStart" ) . ValueGeneratedOnAddOrUpdate ( ) ;
2362
+ e . Property < DateTime > ( "SystemTimeEnd" ) . ValueGeneratedOnAddOrUpdate ( ) ;
2363
+ e . HasKey ( "Id" ) ;
2364
+
2365
+ e . ToTable ( "Customers" , tb => tb . IsTemporal ( ttb =>
2366
+ {
2367
+ ttb . UseHistoryTable ( "HistoryTable" , "historySchema" ) ;
2368
+ ttb . HasPeriodStart ( "SystemTimeStart" ) ;
2369
+ ttb . HasPeriodEnd ( "SystemTimeEnd" ) ;
2370
+ } ) ) ;
2371
+ } ) ;
2372
+ } ,
2373
+ model =>
2374
+ {
2375
+ var table = Assert . Single ( model . Tables ) ;
2376
+ Assert . Equal ( "Customers" , table . Name ) ;
2377
+ Assert . Equal ( true , table [ SqlServerAnnotationNames . IsTemporal ] ) ;
2378
+ Assert . Equal ( "HistoryTable" , table [ SqlServerAnnotationNames . TemporalHistoryTableName ] ) ;
2379
+ Assert . Equal ( "historySchema" , table [ SqlServerAnnotationNames . TemporalHistoryTableSchema ] ) ;
2380
+ Assert . Equal ( "SystemTimeStart" , table [ SqlServerAnnotationNames . TemporalPeriodStartPropertyName ] ) ;
2381
+ Assert . Equal ( "SystemTimeEnd" , table [ SqlServerAnnotationNames . TemporalPeriodEndPropertyName ] ) ;
2382
+
2383
+ Assert . Collection (
2384
+ table . Columns ,
2385
+ c => Assert . Equal ( "Id" , c . Name ) ,
2386
+ c => Assert . Equal ( "Name" , c . Name ) ) ;
2387
+ Assert . Same (
2388
+ table . Columns . Single ( c => c . Name == "Id" ) ,
2389
+ Assert . Single ( table . PrimaryKey ! . Columns ) ) ;
2390
+ } ) ;
2391
+
2392
+ AssertSql (
2393
+ @"IF SCHEMA_ID(N'myDefaultSchema') IS NULL EXEC(N'CREATE SCHEMA [myDefaultSchema];');" ,
2394
+ //
2395
+ @"IF SCHEMA_ID(N'historySchema') IS NULL EXEC(N'CREATE SCHEMA [historySchema];');" ,
2396
+ //
2397
+ @"CREATE TABLE [myDefaultSchema].[Customers] (
2398
+ [Id] int NOT NULL,
2399
+ [Name] nvarchar(max) NULL,
2400
+ [SystemTimeEnd] datetime2 GENERATED ALWAYS AS ROW END HIDDEN NOT NULL,
2401
+ [SystemTimeStart] datetime2 GENERATED ALWAYS AS ROW START HIDDEN NOT NULL,
2402
+ CONSTRAINT [PK_Customers] PRIMARY KEY ([Id]),
2403
+ PERIOD FOR SYSTEM_TIME([SystemTimeStart], [SystemTimeEnd])
2404
+ ) WITH (SYSTEM_VERSIONING = ON (HISTORY_TABLE = [historySchema].[HistoryTable]));" ) ;
2405
+ }
2406
+
2291
2407
[ ConditionalFact ]
2292
2408
public virtual async Task Create_temporal_table_with_default_schema_for_table_and_explicit_history_table_schema_provided ( )
2293
2409
{
@@ -2783,8 +2899,8 @@ await Test(
2783
2899
e . Property < int > ( "Number" ) ;
2784
2900
} ) ,
2785
2901
builder =>
2786
- {
2787
- } ,
2902
+ {
2903
+ } ,
2788
2904
model =>
2789
2905
{
2790
2906
var table = Assert . Single ( model . Tables ) ;
0 commit comments