54 lines
2.9 KiB
C#
54 lines
2.9 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
|
|
using EntityFrameworkCore.Domain;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace EntityFrameworkCore.Data;
|
|
|
|
public class DeadBallZoneLeagueDbContext : DbContext
|
|
{
|
|
private string DbPath;
|
|
public DeadBallZoneLeagueDbContext()
|
|
{
|
|
// In Ubuntu 24.04, the file is created here: /home/user/.local/share
|
|
var folder = Environment.SpecialFolder.LocalApplicationData;
|
|
var path = Environment.GetFolderPath(folder);
|
|
DbPath = Path.Combine(path, "DeadBallZoneLeague_EFCore.db");
|
|
}
|
|
public DbSet<Team> Teams { get; set; }
|
|
public DbSet<Coach> Coaches { get; set; }
|
|
public DbSet<League> Leagues { get; set; }
|
|
public DbSet<Match> Matches { get; set; }
|
|
|
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
|
{
|
|
optionsBuilder.UseSqlite($"Data source={DbPath}")
|
|
// .UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking) // Do not use tracking, set globally on all queries.
|
|
.LogTo(Console.WriteLine, LogLevel.Information)
|
|
.EnableSensitiveDataLogging() // Do not allow this in Production.
|
|
.EnableDetailedErrors(); // Do not allow this in Production.
|
|
}
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
{
|
|
modelBuilder.Entity<Team>().HasData(
|
|
// Use hardcoded dates, not dynamic data such as new DateTimeOffset.UtcNow.DateTime for seeding.
|
|
new Team { Id = 1, Name = "Neo Delhi", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33)},
|
|
new Team { Id = 2, Name = "Voodoo", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33) },
|
|
new Team { Id = 3, Name = "Penal X", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33) },
|
|
new Team { Id = 4, Name = "Neo Tokyo", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33) },
|
|
new Team { Id = 5, Name = "Neo Barcelona", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33) },
|
|
new Team { Id = 6, Name = "Neo Manchester", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33) },
|
|
new Team { Id = 7, Name = "Neo Bangkok", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33) },
|
|
new Team { Id = 8, Name = "Neo Amsterdam", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33) },
|
|
new Team { Id = 9, Name = "Killaklowns", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33) },
|
|
new Team { Id = 10, Name = "Sol", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33) },
|
|
new Team { Id = 11, Name = "DEC", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33) },
|
|
new Team { Id = 12, Name = "Leopards", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33) },
|
|
new Team { Id = 13, Name = "Harlequins", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33) },
|
|
new Team { Id = 14, Name = "Gladiators", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33) },
|
|
new Team { Id = 15, Name = "Fiz-O", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33) }
|
|
);
|
|
}
|
|
}
|