-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfigure.Db.cs
More file actions
30 lines (24 loc) · 1.18 KB
/
Configure.Db.cs
File metadata and controls
30 lines (24 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
using Microsoft.EntityFrameworkCore;
using ServiceStack.Data;
using ServiceStack.OrmLite;
using MyApp.Data;
using Microsoft.EntityFrameworkCore.Diagnostics;
[assembly: HostingStartup(typeof(MyApp.ConfigureDb))]
namespace MyApp;
public class ConfigureDb : IHostingStartup
{
public void Configure(IWebHostBuilder builder) => builder
.ConfigureServices((context, services) => {
var connectionString = context.Configuration.GetConnectionString("DefaultConnection")
?? "DataSource=App_Data/app.db;Cache=Shared";
services.AddOrmLite(options => options.UseSqlite(connectionString));
// $ dotnet ef migrations add CreateIdentitySchema
// $ dotnet ef database update
services.AddDbContext<ApplicationDbContext>(options => {
options.UseSqlite(connectionString, b => b.MigrationsAssembly(nameof(MyApp)));
options.ConfigureWarnings(w => w.Ignore(RelationalEventId.PendingModelChangesWarning));
});
// Enable built-in Database Admin UI at /admin-ui/database
services.AddPlugin(new AdminDatabaseFeature());
});
}