title: How do you insert foreign keys with Dynamic Data
body: <p>I am having trouble with foreign keys Dynamic Data and entity framework 4.0. It feels like there is a problem with the entity association but I am not sure. I have multiple fields representing the foreign key on the insert page. When I try and insert data I get an error A dependent property in a ReferentialConstraint is mapped to a store-generated column.
   Column: 'CommentId'</p>
  
  <p>My data is a very basic one to many relationship, the foreign key in question is BookId in the Comment Table.</p>
  
  <p>Books</p>
  
  <ul>
  <li>BookId</li>
  <li>BookHref</li>
  </ul>
  
  <p>Comments</p>
  
  <ul>
  <li>CommentId</li>
  <li>User</li>
  <li>Comment</li>
  <li>BookId</li>
  </ul>
  
  <p>I create the FOREIGN KEY with the following sql script.</p>
  
  <pre><code>ALTER TABLE [dbo].[Comments]  WITH CHECK ADD  CONSTRAINT [FK_Comments_Books] FOREIGN KEY([CommentId])
  REFERENCES [dbo].[Books] ([BookId])
  </code></pre>
  
  <p>Entity Framework Generates the following XML</p>
  
  <pre><code>&lt;EntityType Name="Books"&gt;
    &lt;Key&gt;
      &lt;PropertyRef Name="BookId" /&gt;
    &lt;/Key&gt;
    &lt;Property Name="BookId" Type="int" Nullable="false" StoreGeneratedPattern="Identity" /&gt;
    &lt;Property Name="Title" Type="nvarchar" Nullable="false" MaxLength="255" /&gt;
    &lt;Property Name="Description" Type="nvarchar" Nullable="false" MaxLength="2000" /&gt;
    &lt;Property Name="Abstract" Type="nvarchar" /&gt;
    &lt;Property Name="UserName" Type="nvarchar" Nullable="false" MaxLength="255" /&gt;
    &lt;Property Name="Image" Type="varbinary(max)" /&gt;
    &lt;Property Name="BookContent" Type="varbinary(max)" /&gt;
    &lt;Property Name="rowguid" Type="uniqueidentifier" Nullable="false" /&gt;
    &lt;Property Name="CreateDate" Type="datetime" /&gt;
    &lt;Property Name="ModifiedDate" Type="datetime" /&gt;
  &lt;/EntityType&gt;
  &lt;EntityType Name="Comments"&gt;
    &lt;Key&gt;
      &lt;PropertyRef Name="CommentId" /&gt;
    &lt;/Key&gt;
    &lt;Property Name="CommentId" Type="int" Nullable="false" StoreGeneratedPattern="Identity" /&gt;
    &lt;Property Name="UserName" Type="nvarchar" Nullable="false" MaxLength="255" /&gt;
    &lt;Property Name="UserComment" Type="nvarchar" Nullable="false" /&gt;
    &lt;Property Name="BookId" Type="int" Nullable="false" /&gt;
  &lt;/EntityType&gt;
  &lt;Association Name="FK_Comments_Books"&gt;
    &lt;End Role="Books" Type="BookStoreModel.Store.Books" Multiplicity="1" /&gt;
    &lt;End Role="Comments" Type="BookStoreModel.Store.Comments" Multiplicity="0..1" /&gt;
    &lt;ReferentialConstraint&gt;
      &lt;Principal Role="Books"&gt;
        &lt;PropertyRef Name="BookId" /&gt;
      &lt;/Principal&gt;
      &lt;Dependent Role="Comments"&gt;
        &lt;PropertyRef Name="CommentId" /&gt;
      &lt;/Dependent&gt;
    &lt;/ReferentialConstraint&gt;
  &lt;/Association&gt;
  </code></pre>
  
  <p>When I let the scaffolding do its thing, I get multiple fields representing the foreign key
  <img src="https://i.stack.imgur.com/rweNc.png" alt="Dynamic Data Output for Comments"></p>