Problem z relacją wiele do wielu

0

Cześć. Tworzę aplikację webową gdzie można rozmawiać taki chat. Ale mam problem z modelami domenowymi. Mam trzy modele
Message:

    public class Message : Entity
    {
        public string Content { get; protected set; }
        public string UserId { get; protected set; }
        public string CreatedAt { get; protected set; }

        public virtual User User { get; protected set; }
        public virtual ICollection<Conversation> Conversations { get; protected set; }


        protected Message()
        {

        }

        public Message(string content, string userId)
        {
            Content = content;
            UserId = userId;
            SetCreatedAt();
        }

        private void SetCreatedAt()
        {
            DateTime now = DateTime.UtcNow;
            CreatedAt = now.ToString("d");
        } 
    }

User:

    public class User : IdentityUser
    {
        public string FirstName { get; protected set; }
        public string LastName { get; protected set; }
        public DateTime CreatedAt { get; protected set; }
        public string CountryCode { get; set; }


        public virtual ICollection<Message> Messages { get; protected set; }
        public virtual ICollection<Conversation> Conversations { get; protected set; }

        public User(string email, string firstName, string lastName)
        {
            FirstName = firstName;
            LastName = lastName;
            Email = email;
            UserName = firstName + " " + lastName;
            EmailConfirmed = false;
            SecurityStamp = Guid.NewGuid().ToString();
            CreatedAt = DateTime.UtcNow;
        }

        protected User()
        {

        }
    }

Conversation:

    public class Conversation : Entity
    {
        public virtual ICollection<User> Users { get; protected set; }
        public virtual ICollection<Message> Messages { get; protected set; }

        public Conversation() { }
    }

Gdy tworzę migrację mam taki błąd:

Unable to determine the relationship represented by navigation property 'Conversation.Users' of type 'ICollection<User>'. Either manually configure the relationship, or ignore this property using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.

Oraz mam taki problem czy dobrze zaprojektowałem modele ? :)

1

Po pierwsze to dlaczego wiadomość jest w relacji 1:N z konwersacjami? To chyba powinno być 1:1.
Po drugie, zastanowiłbym się nad sensem bezpośredniego przypisywania wiadomości użytkownikowi, zrobiłbym to raczej tak, że użytkownik byłby w relacji 1:N z konwersacjami i konwersacja w 1:N z wiadomościami. Wtedy używając prostego joina możesz wyciągnąć wszystkie wiadomości użytkownika z wszystkich konwersacji lub użyć jakiegoś filtra.

A co do samego N:N - nie wiem czy w EF Core coś się zmieniło od czasów EF6, ale jakiś czas temu najłatwiejszym sposobem na załatwienie tej relacji była tabelka łącząca.

1 użytkowników online, w tym zalogowanych: 0, gości: 1