27 lines
1.0 KiB
C#
27 lines
1.0 KiB
C#
using MessageService.Domain.Entities;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
|
|
|
namespace MessageService.Infrastructure.Configs
|
|
{
|
|
public class ConversationConfig : IEntityTypeConfiguration<Conversation>
|
|
{
|
|
public void Configure(EntityTypeBuilder<Conversation> 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<string>("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");
|
|
|
|
}
|
|
}
|
|
}
|