title: Two Foreign Keys in Entity Framework Core
body: <p>I am using Code First approach while creating Database using Entity Framework Core. I would like to create two foreign keys pointing the same table. 
  My example shows User table which will hold userID and Message table which will hold both Receiver ID and Sender ID (what means both values have to point the same table).</p>
  
  <p>Code for User:</p>
  
  <pre><code>public class User
  {
      [Key]
      [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
      public int Id { get; set; }
  
      [Required]
      [MaxLength(50)]
      public string UserName { get; set; }
      [Required]
      [MaxLength(50)]
      public string Password { get; set; }
  
      public virtual ICollection&lt;Message&gt; MessagesSent { get; set; }
      public virtual ICollection&lt;Message&gt; MessagesReceived { get; set; }
  }
  </code></pre>
  
  <p>For Message: </p>
  
  <pre><code>public class Message
  {
      [Key]
      [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
      public int id { get; set; }
  
      public User Sender { get; set; }
      public User Receiver { get; set; }
      public int senderId { get; set; }
      public int receiverId { get; set; }
  
      [MaxLength(500)]
      public string message { get; set; }
  
  }
  </code></pre>
  
  <p>I am using ASP.NET Core 2 and I am a newbie. 
  I was trying to use <a href="https://stackoverflow.com/questions/5559043/entity-framework-code-first-two-foreign-keys-from-same-table" title="this">this</a> solution, but unfortunately, I couldn't manage to override OnModelCreating method. It shows that it doesn't exist.</p>
  
  <p>PS. don't mind password field, it is only for testing purpose.</p>
  
  <p>Thank you!</p>