-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathSessionContext.cs
More file actions
38 lines (36 loc) · 1.24 KB
/
SessionContext.cs
File metadata and controls
38 lines (36 loc) · 1.24 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
31
32
33
34
35
36
37
38
using FireCore.Data.Models;
using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore;
namespace FireCore.Data.Database
{
//https://github.com/karenpayneoregon/ef-code-8-samples/blob/master/BooksApp/Data/BookContext.cs
//https://learn.microsoft.com/en-us/ef/core/cli/dotnet
//https://stackoverflow.com/questions/43709657/how-to-get-root-directory-of-project-in-asp-net-core-directory-getcurrentdirect
public class SessionContext : DbContext
{
public virtual DbSet<SessionDbEntity> SessionDb { get; set; }
public string? ConnectionString { get; set; }
public SessionContext(IWebHostEnvironment webHostEnvironment)
{
ConnectionString = "Sessions.db";
}
public SessionContext(DbContextOptions<SessionContext> options)
: base(options)
{
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlite($"Data Source={ConnectionString}");
base.OnConfiguring(optionsBuilder);
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<SessionDbEntity>(model =>
{
model.Property(e => e.DateTime).HasDefaultValue(DateTimeOffset.Now);
modelBuilder.Entity<SessionDbEntity>();
});
base.OnModelCreating(modelBuilder);
}
}
}