title: To add navigation property without foreign key in EF Core, DB-first migration with .NET Core Web API
body: <p>I am working with an existing system and updating it to .NET Core, Web API and EF Core.</p>
  
  <p>The existing system has 2 tables:</p>
  
  <ul>
  <li>Parent table: Id, name, etc..</li>
  <li>Child table: Id, ParentId, name, etc..</li>
  </ul>
  
  <p>Though <code>ParentId</code> exists in the child table, there is no foreign key reference, but I want to be able to use include when I query the parent. I have asked not to add FK as part of deleting they are putting -ve values to <code>parentId</code> column. This way they can bring it back and a legacy system was built that way.</p>
  
  <p>Now, in db-first migration how can I specify a navigation property without fk so my EF Core to act relational; or at least return them together. Adding nullable foreign key is not an option as it will break the system when -ve values are added.</p>
  
  <p>I do have suggested for full cleanup of DB and getting rid of -ve values but that involves lots of testing and no deliverable. So long story short how to add navigation property without foreign key in database first migration ?</p>
  
  <p>I tried adding collection and virtual entry in the model, but after migration it got overwritten. I have added this by using HasMany on modelbuilder as per this document - <a href="https://docs.microsoft.com/en-us/ef/core/modeling/relationships?tabs=fluent-api%2Cfluent-api-simple-key%2Csimple-key" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/ef/core/modeling/relationships?tabs=fluent-api%2Cfluent-api-simple-key%2Csimple-key</a></p>
  
  <p>But scaffolding is overriding my navigation property</p>