Rework
This commit is contained in:
33
SQLiteEF/Context.cs
Normal file
33
SQLiteEF/Context.cs
Normal file
@ -0,0 +1,33 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace SQLiteEF;
|
||||
|
||||
public class Context(IConfiguration configuration) : DbContext
|
||||
{
|
||||
public DbSet<Player> Players { get; set; }
|
||||
public DbSet<Game> Games { get; set; }
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
optionsBuilder.UseSqlite(configuration.GetConnectionString("DefaultConnection"));
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<Player>()
|
||||
.HasMany<Game>(p => p.Games)
|
||||
.WithMany(g => g.PlayedBy);
|
||||
modelBuilder.Entity<Player>()
|
||||
.Navigation(p => p.Games)
|
||||
.AutoInclude();
|
||||
modelBuilder.Entity<TrackedTime>()
|
||||
.HasOne<Player>(p => p.Player)
|
||||
.WithMany(p => p.TrackedTimes)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
modelBuilder.Entity<TrackedTime>()
|
||||
.HasOne<Game>(p => p.Game)
|
||||
.WithMany(g => g.TrackedTimes)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user