finished documentation for installation, database usage and authentication

This commit is contained in:
2024-11-21 16:55:56 +01:00
parent 986c5cebde
commit eef03c152d
6 changed files with 138 additions and 3 deletions

View File

@@ -0,0 +1,37 @@
# Database initialization
You also need to initialize the data source with the tables from HopFrame
## Create a DbContext
1. Create a c# class that inherits from the `HopDbContextBase` and add a data source (In the example Sqlite is used)
```csharp
public class DatabaseContext : HopDbContextBase {
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) {
base.OnConfiguring(optionsBuilder);
optionsBuilder.UseSqlite("...");
}
}
```
**IMPORTANT:** You need to leave the `base.OnConfiguring(optionsBuilder)` in place so the HopFrame model relations are set correctly.
<p>&nbsp;</p>
2. Register the `DatabaseContext` as a service
```csharp
builder.Services.AddDbContext<DatabaseContext>();
```
3. Create a database migration
```bash
dotnet ef migrations add Initial
```
4. Apply the migration to the data source
```bash
dotnet ef database update
```