title: Entity Framework Core Database First - Multiple Foreign keys to one table
body: <h2>Background Information</h2>
  
  <p>I am currently working with EF Core using a database first implementation.</p>
  
  <p>Current tables</p>
  
  <pre><code>Fizz
  {
      [Id] INT
      [Category] varchar
      [Value] varchar
  }
  
  Buzz
  {
      [Id] UniqueIdentifier
      [TypeId1] INT
      [TypeId2] INT
      CONSTRAINT [FK_Buzz_Fizz_1] FOREIGN KEY ([TypeId1] REFERENCES [Fizz][Id]) 
      CONSTRAINT [FK_Buzz_Fizz_2] FOREIGN KEY ([TypeId2] REFERENCES [Fizz][Id])
  }
  </code></pre>
  
  <p>Fizz currently acts a lookup table. Doing this allows for a single data repository to be used to find different values by category. </p>
  
  <p>Buzz is a table that has two different type values to be stored e.g. TypeId1 could be brand which would exist in Fizz as (id, Brands, Nestle) and TypeId2 could be a flavor which would exist in Fizz as (id, Flavors, Grape).</p>
  
  <h2>The Issue</h2>
  
  <p>I scaffold the db to create the Data Models. 
  When running the application the following occurrs:</p>
  
  <blockquote>
    <p>InvalidOperationException: Unable to determine the relationship represented by navigation property 'Buzz.TypeId1' of type 'Fizz'. Either manually configure the relationship, or ignore this property using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.</p>
  </blockquote>
  
  <p>One solution that has occurred to me is to break this lookup table (Fizz) into multiple tables that way the references could be resolved by not having duplicate types used for Foreign Keys. </p>
  
  <p>This would require re-work of the logic for the current data repository to either access multiple tables or be split into multiple data repos.</p>
  
  <p>Another solution would be to modify the DBContext that is generated and use DataAnnotations on the DataModel. I would like to avoid doing this as the Context and Models will be regenerated in the future and these changes will be overwritten. </p>
  
  <p>Is there a way to have a datamodel generated from a table that has multiple Foreign Keys to a single table without having to modify the generated code?</p>