title: How to get yet-to-be-created ID in Linq/Entity framework
body: <p>I have two table like this:</p>
  
  <pre><code>**Complaint**
  -Id
  -CreatedBy
  -CreatedDate
  ....
  
  **Solution**
  -Id
  -ComplaintId
  </code></pre>
  
  <p>Sometimes, a complaint has an instant solution, which means, when it is created, a solution is also created. The Database is Oracle, and to insert new record into database, I set the StoredGeneratePattern to Identity and use trigger to insert a sequence's value. </p>
  
  <pre><code>here my code:    
  
  using (var context = new Entities())
          {
          var complaint = new Complaint
                              {
                                  Title = TitleTextBox.Text.Trim(),
                                  CreatedBy = CurrentUser.UserID,
                                  Description = DescriptionTextBox.Text.Trim(),
                                  ServiceId = Convert.ToDecimal(ddlService2.Value),
                                  Contact = ContactTextBox.Text.Trim(),
                                  CreatedDate = DateTime.Now,
                                  Customer = txtUserName.Text.Trim(),
                                  ResellerId = CurrentUser.ResellerID,
                                  Status = ComplaintStatus.GetStatusCode("New complaint")
                              };
          if (CompletedCheckBox.Checked)
          {
              complaint.Status = ComplaintStatus.GetStatusCode("Completed");
              var solution = new Solution
                                 {
                                     CreatedBy = CurrentUser.UserID,
                                     CreatedDate = DateTime.Now,
                                     SolutionDesc = DescriptionTextBox.Text,
                                     ComplaintId = complaint.Id
                                 };            
              context.Solutions.AddObject(solution);
  
          }
  
              context.Complaints.AddObject(complaint);
              if(context.SaveChanges() &gt; 0)
              {
                  ResetFrom();
                  return true;
              }
  
          }
  </code></pre>
  
  <p>the problem is, I can't get the id of newly created complaint to set the field in the solution. How can I do that?</p>
  
  <p>Thank you.</p>