pure sql baybeee
This commit is contained in:
1 parent
e5110d04a6
commit
34aed0a436
12 files changed
+173
-39
No files matched your search
@@ -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; }
|
||||
|
||||
Reference in new issue
Block a user