using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; namespace Iceshrimp.Backend.Core.Database.Tables; [Table("promo_note")] [Index(nameof(UserId))] public class PromoNote { [Key] [Column("noteId")] [StringLength(32)] public string NoteId { get; set; } = null!; [Column("expiresAt")] public DateTime ExpiresAt { get; set; } /// /// [Denormalized] /// [Column("userId")] [StringLength(32)] public string UserId { get; set; } = null!; [ForeignKey(nameof(NoteId))] [InverseProperty(nameof(Tables.Note.PromoNote))] public virtual Note Note { get; set; } = null!; private class EntityTypeConfiguration : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder entity) { entity.Property(e => e.UserId).HasComment("[Denormalized]"); entity.HasOne(d => d.Note) .WithOne(p => p.PromoNote) .OnDelete(DeleteBehavior.Cascade); } } }