title: One to one relationship, different key column name, Entity Framework, Code First approach
body: <p>I have two tables that have already been created. <code>Document</code> and <code>DocumentStyle</code>. They have a one to one relationship through the <code>DocumentID</code> column. However, it is called <code>Id</code> in <code>Document</code> table, and <code>DocumentId</code> in <code>DocumentStyle</code> table.</p>
  <p>Something like this</p>
  <pre><code>Document            DocumentStyle 
  |----------|        |----------------|
  |Id - Key  |&lt;------&gt;|DocumentId- key |
  |Name-VChar|        |Color     -VChar|
  |Desc-VChar|        |Font      VChar |
  |----------|        |----------------|
  </code></pre>
  <p>I'm getting the following error in VS</p>
  <blockquote>
  <p>The ForeignKeyAttribute on property 'DocumentStyle' on type
  'KII.Models.Document' is not valid.
  The foreign key name 'DocumentId' was
  not found on the dependent type
  'KII.Models.Document'. The Name value
  should be a comma separated list of
  foreign key property names.</p>
  </blockquote>
  <p>This is part of the code for the Document model class</p>
  <pre class="lang-cs prettyprint-override"><code>[ForeignKey(&quot;DocumentId&quot;)]  
  public DocumentStyle DocumentStyle { get;set; }
  </code></pre>
  <p>EDIT:</p>
  <p>This is the code of my classes.</p>
  <pre class="lang-cs prettyprint-override"><code>public class Document
  {
      [Key]
      public int ID { get; set; }
      
      public string Name { get; set; }
      public int FundId { get; set; }
      public int ClientId { get; set; }
          
      [ForeignKey(&quot;FundId&quot;)]
      public Fund Fund { get; set; }
  
      [ForeignKey(&quot;ClientId&quot;)]
      public Client Client { get; set; }
      
      [ForeignKey(&quot;ID&quot;)]
      public DocumentStyle DocumentStyle { get; set; }
          
      public Document()
      {
  
      }
  
      public Document(DocumentStyle documentStyle)
      {
          DocumentStyle = documentStyle;
      }
  
  }
  
  public class DocumentStyle
  {
      public DocumentStyle()
      {
  
      }
  
      [Key]
      [DisplayName(&quot;Document ID&quot;)]
      public int DocumentId { get; set; }
  
      [ForeignKey(&quot;DocumentId&quot;)]
      public Document Document { get; set; }
  
      [DisplayName(&quot;Title Foreground Color&quot;)]
      public string TitleForegroundColor { get; set; }
  
      [DisplayName(&quot;Title Background Color&quot;)]
      public string TitleBackgroundColor { get; set; }
  
      [DisplayName(&quot;Title Font Family&quot;)]
      public string TitleFontFamily { get; set; }
  
      [DisplayName(&quot;Title Font Size&quot;)]
      public string TitleFontSize { get; set; }
  
      [DisplayName(&quot;Title Font Style&quot;)]
      public string TitleFontStyle { get; set; }
  
      [DisplayName(&quot;Title Font Weight&quot;)]
      public string TitleFontWeight { get; set; }
  
      [DisplayName(&quot;Title Text Decoration&quot;)]
      public string TitleTextDecoration { get; set; }
  
      [DisplayName(&quot;Section Title Foreground Color&quot;)]
      public string SectionTitleForegroundColor { get; set; }
  
      [DisplayName(&quot;Section Title Background Color&quot;)]
      public string SectionTitleBackgroundColor { get; set; }
  
      [DisplayName(&quot;Section Title Font Family&quot;)]
      public string SectionTitleFontFamily { get; set; }
  
      [DisplayName(&quot;Section Title Font Size&quot;)]
      public string SectionTitleFontSize { get; set; }
  
      [DisplayName(&quot;Section Title Font Styled&quot;)]
      public string SectionTitleFontStyle { get; set; }
  
      [DisplayName(&quot;Section Title Font Weight&quot;)]
      public string SectionTitleFontWeight { get; set; }
  
      [DisplayName(&quot;Section Title Text Decoration&quot;)]
      public string SectionTitleTextDecoration { get; set; }
  
      [DisplayName(&quot;Paragraph Foreground Color&quot;)]
      public string ParagraphForegroundColor { get; set; }
  
      [DisplayName(&quot;Paragraph Background Color&quot;)]
      public string ParagraphBackgroundColor { get; set; }
  
      [DisplayName(&quot;Paragraph Font Family&quot;)]
      public string ParagraphFontFamily { get; set; }
  
      [DisplayName(&quot;Paragraph Font Size&quot;)]
      public string ParagraphFontSize { get; set; }
  
      [DisplayName(&quot;Paragraph Font Style&quot;)]
      public string ParagraphFontStyle { get; set; }
  
      [DisplayName(&quot;Paragraph Font Weight&quot;)]
      public string ParagraphFontWeight { get; set; }
  
      [DisplayName(&quot;Paragraph Text Decoration&quot;)]
      public string ParagraphTextDecoration { get; set; }
  
      [DisplayName(&quot;Logo&quot;)]
      public byte[] Logo { get; set; }
  }
  </code></pre>