Files
HopFrame/debug/TestApplication/DatabaseContext.cs
Leon Hoppe ff2634ff41
All checks were successful
HopFrame CI / build (push) Successful in 44s
HopFrame CI / test (push) Successful in 52s
Started working on frontend
2026-02-25 16:33:46 +01:00

26 lines
708 B
C#

using Microsoft.EntityFrameworkCore;
using TestApplication.Models;
namespace TestApplication;
public class DatabaseContext(DbContextOptions<DatabaseContext> options) : DbContext(options) {
public DbSet<User> Users { get; set; }
public DbSet<Post> Posts { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder) {
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Post>()
.HasKey(p => p.Id);
modelBuilder.Entity<User>()
.HasKey(u => u.Id);
modelBuilder.Entity<User>()
.HasMany(u => u.Posts)
.WithOne(p => p.Sender)
.OnDelete(DeleteBehavior.Cascade);
}
}