мои настройки приложения:
Код: Выделить всё
{
"ConnectionStrings": {
"MonitorDb": "Data Source=monitor.db"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
},
"EventLog": {
"LogLevel": {
"Default": "Information"
}
}
},
"DetailedErrors": true,
"AllowedHosts": "*",
"Kestrel": {
"Endpoints": {
"Http": {
"Url": "http://localhost:5100"
}
}
}
}
Код: Выделить всё
public class ApplicationDbContext(DbContextOptions options) :
DbContext(options)
{
public DbSet Configurations { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity().HasData(
new ConfigurationModel
{
Id = 1,
ClientKey = "1",
HubAddress = "http://localhost",
HubPort = "5100",
HubName = "monitorhub"
}
);
base.OnModelCreating(modelBuilder);
}
}
Код: Выделить всё
// create database if not exists
using (var scope = app.Services.CreateScope())
{
var dbContext = scope.ServiceProvider.GetRequiredService();
dbContext.Database.EnsureCreated();
}
Подробнее здесь: https://stackoverflow.com/questions/792 ... 3-database
Мобильная версия