47 lines
1.3 KiB
C#
47 lines
1.3 KiB
C#
namespace Hutopy.Modules.Creators.Data;
|
|
|
|
public class CreatorsDbContext(
|
|
DbContextOptions<CreatorsDbContext> options)
|
|
: DbContext(options)
|
|
{
|
|
public const string SchemaName = "Creators";
|
|
|
|
public DbSet<Creator> Creators => Set<Creator>();
|
|
public DbSet<Slugs> Slugs => Set<Slugs>();
|
|
|
|
protected override void OnModelCreating(
|
|
ModelBuilder modelBuilder)
|
|
{
|
|
modelBuilder.HasDefaultSchema(SchemaName);
|
|
|
|
modelBuilder
|
|
.Entity<Slugs>()
|
|
.Property(x => x.NormalizedName)
|
|
.HasComputedColumnSql("LOWER(\"Name\")", true);
|
|
|
|
modelBuilder
|
|
.Entity<Slugs>()
|
|
.HasIndex(x => x.NormalizedName)
|
|
.IsUnique();
|
|
|
|
modelBuilder
|
|
.Entity<Creator>()
|
|
.Property(c => c.IsDeleted)
|
|
.HasComputedColumnSql("\"DeletedAt\" IS NOT NULL", true); // bool
|
|
|
|
modelBuilder
|
|
.Entity<Creator>()
|
|
.OwnsOne<Socials>(x => x.Socials)
|
|
.ToTable(nameof(Socials));
|
|
|
|
modelBuilder
|
|
.Entity<Creator>()
|
|
.OwnsOne<Presentation>(x => x.Presentation)
|
|
.ToTable(nameof(Presentation));
|
|
|
|
modelBuilder
|
|
.Entity<Creator>()
|
|
.HasQueryFilter(c => !c.IsDeleted);
|
|
}
|
|
}
|