AnsonBot/AnsonBot.Core/BotDbContext.cs

24 lines
686 B
C#
Raw Permalink Normal View History

2026-07-30 19:47:39 +00:00
using Microsoft.EntityFrameworkCore;
namespace AnsonBot.Core;
public class BotDbContext : DbContext
{
public BotDbContext(DbContextOptions<BotDbContext> options) : base(options) { }
public DbSet<PlaySession> PlaySessions => Set<PlaySession>();
protected override void OnModelCreating(ModelBuilder b)
{
var session = b.Entity<PlaySession>();
session.Ignore(s => s.Duration);
// Main lookup: "is this player currently online" and per-player history.
session.HasIndex(s => new { s.PlayerId, s.EndedUtc });
// Supports finding all open sessions on startup for crash recovery.
session.HasIndex(s => s.EndedUtc);
}
}