title: EF Core - Multiple references to the same table
body: <p>Using Entity Framework Core (5.0.1) code first I'm having trouble implementing a class that has two references to another  class.</p>
  <p>This is basically the structure I want:</p>
  <pre><code>public class Location
  {
      public int Id { get; set; }
  
      public string Name { get; set; }
  }
  
  
  public class Race
  {
      public int Id { get; set; }
  
      public string Title { get; set; }
  
      public int? StartLocationId { get; set; }
      public Location StartLocation { get; set; }
  
      public int? EndLocationId { get; set; }
      public Location EndLocation { get; set; }
  }
  </code></pre>
  <p>This actually works fine, but as I'm implementing the form to create a new Race I want to add some validation attributes:</p>
  <pre><code>public class Race
  {
      public int Id { get; set; }
  
      [Required]
      public string Title { get; set; }
  
      [Required]
      public int? StartLocationId { get; set; }
      public Location StartLocation { get; set; }
  
      [Required]
      public int? EndLocationId { get; set; }
      public Location EndLocation { get; set; }
  }
  </code></pre>
  <p>The Required attributes on the location references makes it impossible to create the tables in the initialization of the database (which I'm currently running at all startups since I'm at the beginning of the development). This is the error message I get:</p>
  <blockquote>
  <p>Introducing FOREIGN KEY constraint
  'FK_Races_Locations_StartLocationId' on table 'Races' may cause cycles
  or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO
  ACTION, or modify other FOREIGN KEY constraints. Could not create
  constraint or index.</p>
  </blockquote>
  <p>As I understand it this has to do with a problem with cascade delete. I'm ok with disabling cascade delete in the database, but I would like the properties to be required for validation in the GUI. Is that even possible?</p>
  <p>For the other relations in my model classes that are not standard I use the Fluent Api to configure, so a solution using that would be best. However, solving the problem is my priority so a solution using attributes is also fine.</p>
  <p>I have found other threads here on StackOverflow with very similiar questions, but none of the suggested solutions have worked for me (some are for Entity Framework, not Core):</p>
  <p><a href="https://stackoverflow.com/questions/57947931/ef-core-multiple-references-to-same-entity">EF Core Multiple References to Same Entity</a>
  <a href="https://stackoverflow.com/questions/54418186/ef-core-2-2-two-foreign-keys-to-same-table">EF Core 2.2 - Two foreign keys to same table</a>
  <a href="https://stackoverflow.com/questions/5559043/entity-framework-code-first-two-foreign-keys-from-same-table">Entity Framework Code First - two Foreign Keys from same table</a>
  <a href="https://stackoverflow.com/questions/30717484/entity-framework-multiple-references-to-same-table">Entity Framework multiple references to same table</a></p>