hallo
This commit is contained in:
37
Desktop/hallo/LEA/Data/AppDbContext.cs
Normal file
37
Desktop/hallo/LEA/Data/AppDbContext.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using LEA.Models;
|
||||
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace LEA.Data;
|
||||
|
||||
public class AppDbContext : IdentityDbContext<ApplicationUser>
|
||||
{
|
||||
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options)
|
||||
{
|
||||
}
|
||||
|
||||
public DbSet<Application> Applications { get; set; } = null!;
|
||||
public DbSet<Contact> Contacts { get; set; } = null!;
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder builder)
|
||||
{
|
||||
base.OnModelCreating(builder);
|
||||
|
||||
builder.Entity<Application>()
|
||||
.HasOne(a => a.User)
|
||||
.WithMany()
|
||||
.HasForeignKey(a => a.UserId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
builder.Entity<Application>()
|
||||
.HasOne(a => a.Contact)
|
||||
.WithOne(c => c.Application)
|
||||
.HasForeignKey<Contact>(c => c.ApplicationId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
builder.Entity<Application>()
|
||||
.Property(a => a.Status)
|
||||
.HasConversion<string>()
|
||||
.HasMaxLength(50);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user