title: Entity Framework : how to change foreign key one field to another
body: <p>I have an EF question for you: I have these two classes</p>
  
  <pre><code>public class Post 
  {
      public long Id {get;set}
      public string Content {get;set;}
      public virtual ICollection&lt;Comment&gt; Comments {get;set;}
  }
  
  public class Comment 
  {
      public long Id {get;set;}
      public string Content {get;set;}
  }
  </code></pre>
  
  <p>I created a database at first with these columns and EF created foreign key with <code>Id</code> column of <code>Post</code> class, but then I added <code>UniqKey</code> column as my new primary key:</p>
  
  <pre><code>public class Post 
  {
      public long Id {get;set}
      public string Content {get;set;}
  
      public string UniqKey {get;set;} //New Field will be my new primary key
  
      public virtual ICollection&lt;Comment&gt; Comments {get;set;}
  }
  </code></pre>
  
  <p>and I want to change my foreign key to use <code>UniqKey</code> instead of <code>Id</code>.</p>
  
  <p>I want to update database without deleting and losing any data.</p>
  
  <p>Any help appreciated </p>
  
  <p>Thanks</p>