C#C
C#3y ago
S-IERRA

❔ EFC Is not loading collection properly

I have the following 2 models in my database, EFC does not seem to be loading it at all for some reason

public record ChatUser : IEntityTypeConfiguration<ChatUser>
{
    public Guid Id { get; set; }
    
    public required string Username { get; set; }
    public required string Email { get; set; }
    public required string HashedPassword { get; set; }
    
    public Guid? RegistrationToken { get; set; }
    public Guid? PasswordResetToken { get; set; }
    
    public virtual ICollection<ChatChannel> Channels { get; set; } = new HashSet<ChatChannel>();
    public virtual ICollection<ChatRelationship> Relationships { get; set; } = new HashSet<ChatRelationship>();

    public void Configure(EntityTypeBuilder<ChatUser> builder)
    {
        builder.Property(x => x.Id)
            .HasDefaultValue(Guid.NewGuid());
    }
}


public record ChatRelationship : IEntityTypeConfiguration<ChatRelationship>
{
    public Guid Id { get; set; }
    
    public required Guid SelfId { get; set; }
    public ChatUser Self { get; set; }
    
    public required Guid OtherUserId { get; set; }
    public ChatUser OtherUser { get; set; }

    public required ChatRelationShipType Type { get; set; } = ChatRelationShipType.None;

    public void Configure(EntityTypeBuilder<ChatRelationship> builder)
    {
        builder.Property(x => x.Id)
            .HasDefaultValue(Guid.NewGuid());
        
        builder.HasKey(f => new { User1Id = f.SelfId, User2Id = f.OtherUserId });

        builder.HasOne(x => x.Self)
            .WithMany(x => x.Relationships)
            .HasForeignKey(x => x.SelfId)
            .OnDelete(DeleteBehavior.Restrict);
        
        builder.HasOne(x => x.OtherUser)
            .WithMany()
            .HasForeignKey(x => x.OtherUserId)
            .OnDelete(DeleteBehavior.Restrict);
    }
}
image.png
image.png
Was this page helpful?