Skip to content

Commit c03c8bd

Browse files
committed
All apps/tests work
1 parent 0daaf43 commit c03c8bd

File tree

8 files changed

+46
-11
lines changed

8 files changed

+46
-11
lines changed

AuthPermissions.BaseCode/DataLayer/EfCode/AuthPermissionsDbContext.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using AuthPermissions.BaseCode.DataLayer.Classes;
55
using AuthPermissions.BaseCode.DataLayer.Classes.SupportTypes;
66
using Microsoft.EntityFrameworkCore;
7+
using Microsoft.EntityFrameworkCore.Diagnostics;
78
using Microsoft.EntityFrameworkCore.Infrastructure;
89
using Microsoft.EntityFrameworkCore.Metadata;
910

@@ -31,11 +32,18 @@ public AuthPermissionsDbContext(DbContextOptions<AuthPermissionsDbContext> optio
3132
{
3233
eventSetup.RegisterEventHandlers(this);
3334
}
34-
3535
ProviderName = Database.ProviderName;
3636
_customConfiguration = customConfiguration;
3737
}
3838

39+
protected override void OnConfiguring(
40+
DbContextOptionsBuilder optionsBuilder)
41+
{
42+
//This allows you to add more that one migration on this database
43+
optionsBuilder.ConfigureWarnings(x => x.Ignore(RelationalEventId.PendingModelChangesWarning));
44+
base.OnConfiguring(optionsBuilder);
45+
}
46+
3947
/// <summary>
4048
/// This overcomes the exception if the class used in the tests which uses the <see cref="IModelCacheKeyFactory"/>
4149
/// to allow testing of an DbContext that works with SqlServer and PostgreSQL

Example3.InvoiceCode/EfCoreCode/InvoicesDbContext.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using AuthPermissions.BaseCode.DataLayer.EfCode;
1010
using Example3.InvoiceCode.EfCoreClasses;
1111
using Microsoft.EntityFrameworkCore;
12+
using Microsoft.EntityFrameworkCore.Diagnostics;
1213

1314
namespace Example3.InvoiceCode.EfCoreCode
1415
{
@@ -24,6 +25,14 @@ public InvoicesDbContext(DbContextOptions<InvoicesDbContext> options, IGetDataKe
2425
DataKey = dataKeyFilter?.DataKey ?? "Bad key";
2526
}
2627

28+
protected override void OnConfiguring(
29+
DbContextOptionsBuilder optionsBuilder)
30+
{
31+
//This allows you to add more that one migration on this database
32+
optionsBuilder.ConfigureWarnings(x => x.Ignore(RelationalEventId.PendingModelChangesWarning));
33+
base.OnConfiguring(optionsBuilder);
34+
}
35+
2736
public DbSet<CompanyTenant> Companies { get; set; }
2837
public DbSet<Invoice> Invoices { get; set; }
2938
public DbSet<LineItem> LineItems { get; set; }
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
22
using Microsoft.EntityFrameworkCore;
3+
using Microsoft.EntityFrameworkCore.Diagnostics;
34

45
namespace Example3.MvcWebApp.IndividualAccounts.Data
56
{
67
public class ApplicationDbContext : IdentityDbContext
78
{
89
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
9-
: base(options)
10+
: base(options) {}
11+
12+
protected override void OnConfiguring(
13+
DbContextOptionsBuilder optionsBuilder)
1014
{
15+
//This allows you to add more that one migration on this database
16+
optionsBuilder.ConfigureWarnings(x => x.Ignore(RelationalEventId.PendingModelChangesWarning));
17+
base.OnConfiguring(optionsBuilder);
1118
}
1219
}
1320
}

Example6.SingleLevelSharding/EfCoreCode/ShardingSingleDbContext.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using AuthPermissions.BaseCode.DataLayer.EfCode;
88
using Example6.SingleLevelSharding.EfCoreClasses;
99
using Microsoft.EntityFrameworkCore;
10+
using Microsoft.EntityFrameworkCore.Diagnostics;
1011

1112
namespace Example6.SingleLevelSharding.EfCoreCode;
1213

@@ -35,6 +36,14 @@ public ShardingSingleDbContext(DbContextOptions<ShardingSingleDbContext> options
3536
Database.SetConnectionString(shardingDataKeyAndConnect.ConnectionString);
3637
}
3738

39+
protected override void OnConfiguring(
40+
DbContextOptionsBuilder optionsBuilder)
41+
{
42+
//This allows you to add more that one migration on this database
43+
optionsBuilder.ConfigureWarnings(x => x.Ignore(RelationalEventId.PendingModelChangesWarning));
44+
base.OnConfiguring(optionsBuilder);
45+
}
46+
3847
public DbSet<CompanyTenant> Companies { get; set; }
3948
public DbSet<Invoice> Invoices { get; set; }
4049
public DbSet<LineItem> LineItems { get; set; }
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
{
2-
"Cache": {
3-
"ShardingEntry-12.10-20240815111004": "{\r\n \"Name\": \"12.10-20240815111004\",\r\n \"DatabaseName\": \"20240815111004-706\",\r\n \"ConnectionName\": \"EastCoastServer\",\r\n \"DatabaseType\": \"SqlServer\"\r\n}",
4-
"ShardingEntry-12.3-20240815110327": "{\r\n \"Name\": \"12.3-20240815110327\",\r\n \"DatabaseName\": \"20240815110327-580\",\r\n \"ConnectionName\": \"EastCoastServer\",\r\n \"DatabaseType\": \"SqlServer\"\r\n}",
5-
"ShardingEntry-12.6-20240815110616": "{\r\n \"Name\": \"12.6-20240815110616\",\r\n \"DatabaseName\": \"20240815110616-695\",\r\n \"ConnectionName\": \"WestCoastServer\",\r\n \"DatabaseType\": \"SqlServer\"\r\n}",
6-
"ShardingEntry-13.18-20240816140829": "{\r\n \"Name\": \"13.18-20240816140829\",\r\n \"DatabaseName\": \"20240816140829-085\",\r\n \"ConnectionName\": \"CentralServer\",\r\n \"DatabaseType\": \"SqlServer\"\r\n}"
7-
},
2+
"Cache": {},
83
"TimeOuts": {}
94
}

Test/DiTestHelpers/ApplicationDbContext.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,21 @@
44
using Microsoft.AspNetCore.Identity;
55
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
66
using Microsoft.EntityFrameworkCore;
7+
using Microsoft.EntityFrameworkCore.Diagnostics;
78

89
namespace Test.DiTestHelpers
910
{
1011
public class ApplicationDbContext : IdentityDbContext
1112
{
1213
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
13-
: base(options)
14+
: base(options) { }
15+
16+
protected override void OnConfiguring(
17+
DbContextOptionsBuilder optionsBuilder)
1418
{
19+
//This allows you to add more that one migration on this database
20+
optionsBuilder.ConfigureWarnings(x => x.Ignore(RelationalEventId.PendingModelChangesWarning));
21+
base.OnConfiguring(optionsBuilder);
1522
}
1623
}
1724

Test/TestData/example3-appsettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"ConnectionStrings": {
3-
"DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=aspnet-Example3.MvcWebApp.IndividualAccounts-66CDC4E0-F9E0-486F-8199-D13455BF1415;Trusted_Connection=True;MultipleActiveResultSets=true"
3+
"DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=Test.Example3.MvcWebApp.IndividualAccounts;Trusted_Connection=True;MultipleActiveResultSets=true"
44
},
55
"Logging": {
66
"LogLevel": {

Test/UnitTests/TestExamples/TestExamplesStartup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public async Task TestExample3RunMethodsSequentiallyAsync()
104104
.AddJsonFile("example3-appsettings.json", optional: false);
105105
builder.Services.AddSingleton<IConfiguration>(configBuilder.Build());
106106

107-
//Regsiter the Example3 invoice DbContext
107+
//Register the Example3 invoice DbContext
108108
builder.Services.AddDbContext<InvoicesDbContext>(options =>
109109
options.UseSqlServer(connectionString, dbOptions =>
110110
dbOptions.MigrationsHistoryTable("SomeNonDefaultHistoryName")));

0 commit comments

Comments
 (0)