I try to setup a class which is UserUserFavourite. It will store the relationship between users if they are following users or followed by users.
To do that I created a class as below:
[Table("UserUserFavorite")]
public class UserUserFavorite
{
[ForeignKey("User1")]
public long UserId1 { get; set; }
public User User1 { get; set; }
[ForeignKey("User2")]
public long UserId2 { get; set; }
public User User2 { get; set; }
}
The user1 is following user2.
In my UserClass I have tow properties:
`public List<UserUserFavorite> Followers{ get; set; }
public List<UserUserFavorite> Followings{ get; set; }`
In my dbcontext I have:
modelBuilder.Entity<UserUserFavorite>().HasKey(sc => new { sc.UserId1, sc.UserId2 });
Then I generate my migration I have the error:
Unable to determine the relationship represented by navigation property 'UserUserFavorite.User1' of type 'User'. Either manually configure the relationship, or ignore this property using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.
What's wrong?