pure sql baybeee

This commit is contained in:
ntr committed 2023-08-30 20:21:08 +10:00
1 parent b7ad479ead
commit 5a7e493d92
12 files changed
+173 -39

No files matched your search

+3 -11
View File
@@ -1,5 +1,7 @@
using System;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using SpaceRace.Shared;
@@ -14,19 +16,8 @@ public class SpaceRaceDbContext : DbContext {
protected override void OnModelCreating(ModelBuilder modelBuilder) {
base.OnModelCreating(modelBuilder);
new SpaceRaceInitialiser(modelBuilder).Seed();
var pbQuery = $$"""
WITH ranked AS (
SELECT *, rank() OVER (ORDER BY "Time" ASC) AS "Position", COUNT("Id") OVER () AS "Completions"
FROM "Laps"
)
SELECT * FROM ranked
""";
modelBuilder.Entity<PbDTO>()
.HasNoKey()
.ToSqlQuery(pbQuery)
.ToTable(null as string);
}
}
@@ -34,6 +25,7 @@ public class SpaceRaceDbContext : DbContext {
[Index(nameof(UserId), nameof(Map), IsUnique = true)]
[Index(nameof(Map))]
public class Lap {
[Key, DatabaseGenerated(DatabaseGeneratedOption.None)]
public Guid Id { get; set; }
public Guid UserId { get; set; }
[Required] public DateTimeOffset Created { get; set; }