summaryrefslogtreecommitdiffstats
path: root/api/WhatApi/Database.cs
blob: 39de79a3a6a7355fbd6115221c176d778b6ec176 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
using Microsoft.EntityFrameworkCore;

namespace WhatApi;

public class Database(DbContextOptions<Database> options) : DbContext(options)
{
    public DbSet<Tables.Content> Content { get; set; }
    public DbSet<Tables.Place> Places { get; set; }
    protected override void OnModelCreating(ModelBuilder b) {
        b.HasPostgresExtension("postgis");
        b.Entity<Tables.Place>(e => {
            e.Property(x => x.Location).HasColumnType($"geometry(point,{Constants.Wgs84SpatialReferenceId})");
            e.HasIndex(x => x.Location).HasMethod("gist");
            e.ToTable("Place");
        });
        b.Entity<Tables.Content>();
        base.OnModelCreating(b);
    }
}