using Microsoft.EntityFrameworkCore; namespace Hutopy.Web.Features.Contents.Data; public class ContentDbContext( DbContextOptions options) : DbContext(options) { public const string SchemaName = "Content"; public DbSet Contents => Set(); public DbSet Creators => Set(); public DbSet Subscriptions => Set(); protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.HasDefaultSchema("Content"); modelBuilder .Entity() .Property(c => c.CreatedAt) .ValueGeneratedOnAdd() .HasDefaultValueSql("CURRENT_TIMESTAMP"); modelBuilder .Entity() .OwnsOne(x => x.About); modelBuilder .Entity() .OwnsOne(x => x.SocialNetworks) .ToTable(nameof(SocialNetworks)); modelBuilder .Entity() .OwnsOne(x => x.ProfileColors) .ToTable(nameof(ProfileColors)); modelBuilder .Entity() .OwnsOne(x => x.StoredDataUrls) .ToTable(nameof(StoredDataUrls)); } public async Task FindByCreatorAliasAsync( string creatorAlias, CancellationToken cancellationToken = default) { ArgumentException.ThrowIfNullOrEmpty(creatorAlias); var user = await Creators.SingleOrDefaultAsync(creator => EF.Functions.Like( creatorAlias, creator.Name), cancellationToken: cancellationToken); return user; } }