using MessageService.Domain.Entities; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; namespace MessageService.Infrastructure.Configs { public class ConversationConfig : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder builder) { builder.ToTable("conversations"); builder.HasKey(x => x.Id); builder.HasIndex(x => x.UserId); builder.HasIndex(x => new { x.UserId, x.ChatType, x.TargetId, x.IsDeleted }); builder.Property("ActiveConversationKey") .HasMaxLength(96) .HasComputedColumnSql( "CASE WHEN `IsDeleted` = 0 THEN CONCAT(`UserId`, ':', `ChatType`, ':', `TargetId`) ELSE NULL END", stored: true); builder.HasIndex("ActiveConversationKey") .IsUnique() .HasDatabaseName("UX_conversations_ActiveConversationKey"); } } }