returning pb
This commit is contained in:
1 parent
9f857aeeda
commit
0b2d4ccd14
7 files changed
+141
-45
No files matched your search
@@ -1,15 +1,32 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
using Server.Models;
|
||||
|
||||
namespace Server;
|
||||
|
||||
public class SpaceRaceDbContext : DbContext {
|
||||
public DbSet<Lap> Laps { get; set; }
|
||||
public DbSet<PbDTO> PbDTO { get; set; }
|
||||
|
||||
public SpaceRaceDbContext(DbContextOptions<SpaceRaceDbContext> options) : base(options) {}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder) {
|
||||
base.OnModelCreating(modelBuilder);
|
||||
new SpaceRaceInitialiser(modelBuilder).Seed();
|
||||
|
||||
modelBuilder.Entity<PbDTO>(pb => {
|
||||
var pbQuery = $$"""
|
||||
WITH ranked AS (
|
||||
SELECT *, rank() OVER (ORDER BY "Time" ASC) AS "Position", COUNT("Id") OVER () AS "Completions"
|
||||
FROM "Laps"
|
||||
)
|
||||
|
||||
SELECT * FROM ranked
|
||||
""";
|
||||
pb.HasNoKey();
|
||||
pb.ToSqlQuery(pbQuery);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user