title: How to define multiple relationships between two entities?
body: <p>I have the scenario where a <strong>user</strong> can upload multiple <strong>photos</strong> (One-to-Many). The <strong>user</strong> also can have <strong>a default photo</strong> (One-to-One). However, I entity framework <strong>core 2.0</strong> tells that he cannot recognize the relationship when I use the following code:</p>
  <pre><code>public class User
  {
      public Guid Id { get; set; }
  
      public ICollection&lt;Photo&gt; Photos{ get; set; }
  
      public Photo DefaultPhoto { get; set; }
      [ForeignKey(&quot;DefaultPhoto&quot;)]
      public Guid DefaultPhotoId { get; set; }
  }
  
  public class Photo
  {
      public Guid Id { get; set; }
  
      public User Owner { get; set; }
  }
  </code></pre>
  <p>How may I achieve these multiple relationships?</p>
  <p>There error shown by EF-Core:</p>
  <blockquote>
  <p>System.InvalidOperationException: 'Unable to determine the relationship represented by navigation property 'Photo.Owner' of type 'User'. Either manually configure the relationship, or ignore this property using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.'</p>
  </blockquote>
  <h3>UPDATE:</h3>
  <p>Adding <code>[InverseProperty(&quot;Photos&quot;)]</code> to the navigation property <strong>Owner</strong> in File Model seems to be working. I am not sure if that is the correct way?</p>
  <p><a href="https://i.stack.imgur.com/b6fcZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/b6fcZ.png" alt="enter image description here" /></a>
  <em>In this image File=Photo; Uploader=Owner (to be comparable with the above model).</em></p>
  <h3>UPDATE 2:</h3>
  <p>I confirm what @Ivan said in the comments, with DataAnnotation approach, I get One-to-Many in two directions instead of One-to-Many and One-to-One. This figure shows the generated database by using <code>InverseProperty</code> (the connection between the to entities show the bi-directional One-to-Many relationship):</p>
  <p><a href="https://i.stack.imgur.com/Ah82h.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ah82h.png" alt="enter image description here" /></a></p>
  <p><em>In this image File=Photo; Uploader=Owner (to be comparable with the above model).</em></p>