Skip to content

Commit 3fbaa31

Browse files
committed
upgrade to overridable db
1 parent 5922eb3 commit 3fbaa31

File tree

6 files changed

+14
-14
lines changed

6 files changed

+14
-14
lines changed

MyApp/Configure.Db.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
using Microsoft.EntityFrameworkCore;
12
using ServiceStack.Data;
23
using ServiceStack.OrmLite;
4+
using MyApp.Data;
35

46
[assembly: HostingStartup(typeof(MyApp.ConfigureDb))]
57

@@ -9,11 +11,17 @@ public class ConfigureDb : IHostingStartup
911
{
1012
public void Configure(IWebHostBuilder builder) => builder
1113
.ConfigureServices((context, services) => {
14+
var connectionString = context.Configuration.GetConnectionString("DefaultConnection")
15+
?? "DataSource=App_Data/app.db;Cache=Shared";
16+
1217
services.AddSingleton<IDbConnectionFactory>(new OrmLiteConnectionFactory(
13-
context.Configuration.GetConnectionString("DefaultConnection")
14-
?? ":memory:",
15-
SqliteDialect.Provider));
18+
connectionString, SqliteDialect.Provider));
1619

20+
// $ dotnet ef migrations add CreateIdentitySchema
21+
// $ dotnet ef database update
22+
services.AddDbContext<ApplicationDbContext>(options =>
23+
options.UseSqlite(connectionString, b => b.MigrationsAssembly(nameof(MyApp))));
24+
1725
// Enable built-in Database Admin UI at /admin-ui/database
1826
services.AddPlugin(new AdminDatabaseFeature());
1927
});

MyApp/Migrations/20231119163430_CreateIdentitySchema.Designer.cs renamed to MyApp/Migrations/20240301000000_CreateIdentitySchema.Designer.cs

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MyApp/Migrations/20231119163430_CreateIdentitySchema.cs renamed to MyApp/Migrations/20240301000000_CreateIdentitySchema.cs

File renamed without changes.

MyApp/Migrations/ApplicationDbContextModelSnapshot.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ partial class ApplicationDbContextModelSnapshot : ModelSnapshot
1515
protected override void BuildModel(ModelBuilder modelBuilder)
1616
{
1717
#pragma warning disable 612, 618
18-
modelBuilder.HasAnnotation("ProductVersion", "8.0.0");
18+
modelBuilder.HasAnnotation("ProductVersion", "8.0.2");
1919

2020
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
2121
{

MyApp/Program.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@
1919
options.MinimumSameSitePolicy = SameSiteMode.Strict;
2020
});
2121

22-
// $ dotnet ef migrations add CreateIdentitySchema
23-
// $ dotnet ef database update
24-
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection") ?? throw new InvalidOperationException("Connection string 'DefaultConnection' not found.");
25-
services.AddDbContext<ApplicationDbContext>(options =>
26-
options.UseSqlite(connectionString, b => b.MigrationsAssembly(nameof(MyApp))));
2722
services.AddDatabaseDeveloperPageExceptionFilter();
2823

2924
services.AddIdentity<ApplicationUser, IdentityRole>(options => {

MyApp/appsettings.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
{
2-
"ConnectionStrings": {
3-
"DefaultConnection": "DataSource=App_Data/app.db;Cache=Shared",
4-
},
52
"Logging": {
63
"LogLevel": {
74
"Default": "Information",

0 commit comments

Comments
 (0)