Cześć,
Chciałbym utworzyć navigation property pomiędzy Message i User, ale dostaję błąd:
Unable to determine the relationship represented by navigation property 'Message.FromUser' of type 'User'. Either manually configure the relationship, or ignore this property using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.
Message wygląda następująco:
namespace MyApplication.DAL.Models
{
public class Message : Base
{
public int FromUserId { get; set; }
public User FromUser { get; set; }
public int ToUserId { get; set; }
public User ToUser { get; set; }
public string Title { get; set; }
public string Text { get; set; }
}
public class MessageConfiguration : IEntityTypeConfiguration<Message>
{
public void Configure(EntityTypeBuilder<Message> builder)
{
builder.HasOne(m => m.FromUser).WithMany(u => u.SentMessages);
builder.HasOne(m => m.ToUser).WithMany(u => u.ReceivedMessages).OnDelete(DeleteBehavior.Restrict);
}
}
}
Zaś User następująco:
public class User : Base
{
public string Name { get; set; }
public string Email { get; set; }
public ICollection<Message> SentMessages { get; set; }
public ICollection<Message> ReceivedMessages { get; set; }
}
W którym miejscu i jak powinienem wywoływać Configure?
Z góry dzięki!