title: Connect parent entity with existing child entity in database using Entity Framework 6
body: <p>I'm using Entity Framework 6 to design and use a database that has a child Table of users which looks like this:</p>
  <pre><code>public class User
  {
      public long Id { get; set; }
      public string UserName { get; set; }
      public string CompanyId { get; set; }
  }
  </code></pre>
  <p>And an Order table that looks like this:</p>
  <pre><code>    public class Order
  {
      public long OrderId { get; set; }
      public int ItemCount { get; set; }
      public DateTime OrderDate{ get; set; }
      ...
  
      public virtual User User { get; set; }
  
  }
  </code></pre>
  <p>In my database, the field representing the User table in Order table is <code>User_Id</code></p>
  <p>Now my issue here (which might be a database design issue) is that before Creating a new User and Order in the database, I want to check if the user exists, and if he does, link it to the new order instead of creating a new User. I have a method that Adds new user if the user doesn't exist and returns either the created or the existing user's <code>Id</code> field value.</p>
  <p>How to Create a new instance of Order that takes the <code>Id</code> value instead of <code>User</code> object to avoid having duplicate users, or is there a better way to handle this Use Case?</p>
  <p>I tried to return the object instead of the UserId, but it saves a new User in the User Table</p>