Övergått till entity framework + lagt till ny tabell

This commit is contained in:
2025-09-02 15:07:21 +02:00
parent b04fc7e06e
commit ddb6719587
22 changed files with 1175 additions and 95 deletions

View File

@ -1,25 +1,32 @@
using GreadyPoang.EntityLayer;
using Microsoft.EntityFrameworkCore;
namespace GreadyPoang.DataLayer.Database
namespace GreadyPoang.DataLayer.Database;
public class DataContext : DbContext
{
public class DataContext : DbContext
public DataContext(DbContextOptions<DataContext> options) : base(options)
{
public DataContext(DbContextOptions<DataContext> options) : base(options)
{
}
//public DbSet<User> Users => Set<User>();
public DbSet<Participant> Participants { get; set; }
}
//public DbSet<User> Users => Set<User>();
public DbSet<Participant> Participants { get; set; }
public DbSet<GamePoint> GamePoints { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Participant>().HasData(
new Participant { ParticipantId = 1, FirstName = "John", LastName = "Doe", Email = "John.Doe@gmail.com" },
new Participant { ParticipantId = 2, FirstName = "Jane", LastName = "Black", Email = "jb@gmail.com" },
new Participant { ParticipantId = 3, FirstName = "Mary", LastName = "White", Email = "mw@gmail.com" }
);
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Participant>().HasData(
new Participant { ParticipantId = 1, FirstName = "John", LastName = "Doe", Email = "John.Doe@gmail.com" },
new Participant { ParticipantId = 2, FirstName = "Jane", LastName = "Black", Email = "jb@gmail.com" },
new Participant { ParticipantId = 3, FirstName = "Mary", LastName = "White", Email = "mw@gmail.com" }
);
modelBuilder.Entity<GamePoint>().HasData(
new GamePoint { GamePointId = 1, ParticipantId = 1, GameHeatId = 0, GameDate = new DateTime(2025, 10, 15, 20, 10, 15), GameHeatRegNr = 1, GameRegPoints = 1050 },
new GamePoint { GamePointId = 2, ParticipantId = 1, GameHeatId = 0, GameDate = new DateTime(2025, 10, 15, 20, 15, 15), GameHeatRegNr = 3, GameRegPoints = 350 },
new GamePoint { GamePointId = 3, ParticipantId = 3, GameHeatId = 0, GameDate = new DateTime(2025, 10, 15, 20, 12, 15), GameHeatRegNr = 2, GameRegPoints = 1000 },
new GamePoint { GamePointId = 4, ParticipantId = 3, GameHeatId = 0, GameDate = new DateTime(2025, 10, 15, 20, 20, 15), GameHeatRegNr = 4, GameRegPoints = 400 }
);
}
}