I am designing a code-fire migration using Entity Framework and have some problem when one object has a List of the same type as itself. Say I have a User
object which has a List<User>
as its Friends
:
public class User
{
[Key]
public int UserId { get; set; }
// some other stuff
public List<User> Friends { get; set; }
}
The problem is EF looks for a foreign key for the User and tries to create one when it couldn't find any:
AddColumn("dbo.Users", "User_UserId", c => c.Int());
I am trying to avoid making UserId
a key and foreign key at the same time, so what's a good practice here?