24 lines
686 B
C#
24 lines
686 B
C#
|
|
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);
|
||
|
|
}
|
||
|
|
}
|