title: linq to sql Association problem with foreign keys
body: <p>I have two simple tables and a big problem with foreign keys: </p>
  
  <ul>
  <li>Sale (SaleID int PK identity)</li>
  <li>SaleDetail (SaleDetailId int PK
  identity, SaleID int FK)</li>
  </ul>
  
  <p>which is a very basic one-to-many parent with children relationship. Of course there are some other fields but they're unrelated as they're not used in the relationship, so I did not include them in the listings.</p>
  
  <p>I mapped the tables to classes in my code:</p>
  
  <pre><code>[Table()]
  public class Sale
  {
      [Column(IsPrimaryKey=true, IsDbGenerated=true, AutoSync=AutoSync.OnInsert)]
      public int SaleId
      {
          get;
          set;
      }
  
      private EntitySet&lt;SaleDetail&gt; saleDetails = new EntitySet&lt;SaleDetail&gt;();
      [Association(OtherKey = "SaleId", Storage = "saleDetails")]
      public EntitySet&lt;SaleDetail&gt; SaleDetails
      {
          get
          {
              return this.saleDetails;
          }
          set
          {
              this.saleDetails.Assign(value);
          }
      }
  </code></pre>
  
  <p>and the other one:</p>
  
  <pre><code>[Table()]
  public class SaleDetail
  {
      [Column(IsPrimaryKey=true, IsDbGenerated=true, UpdateCheck=UpdateCheck.Never)]
      public int SaleDetailId
      {
          get;
          set;
      }
  
      [Column()]
      public int SaleId
      {
          get;
          set;
      }
  </code></pre>
  
  <p>Then I try to create a new Sale and add a couple of child objects.</p>
  
  <pre><code>Sale s = new Sale();
  s.SaleDetails.Add(new SaleDetail());
  s.SaleDetails.Add(new SaleDetail());
  </code></pre>
  
  <p>and in the last step I try to add the new objects:</p>
  
  <pre><code>using (DataContext dc = new DataContext(Database.ConnectionString))
  {
    var sales = dc.GetTable&lt;Sale&gt;();
  
    sales.InsertOnSubmit(s);
    dc.SubmitChanges();
  }
  </code></pre>
  
  <p>the following procedure results in a foreign key problem - the child records are added with value 0 in the "SaleId" (FK) column. The parent record is added properly and the SaleId primary key gets its autogenerated value. What can I do to get the SaleId field set automatically in the child objects based on the value of the newly inserted parent?</p>