title: Add parent row and add child for that new parent row
body: <p>i am creating new record in 'Timecard' table and at the same time i want to create one record in 'TimecardStatusTrack' table using entity framework. i am able to create parent record but while adding child record i am getting exception. the code i have written is like</p>
  
  <pre><code>var fEmpManager = DependencyContainer.GetInstance&lt;IBusinessService&lt;FacilityEmployee&gt;&gt;();
  int timecardStatusDidNotWork =
  Convert.ToInt32(GeneralCodeId.TimeCardStatusDidNotWork, CultureInfo.InvariantCulture);
  Timecard timecard = new Timecard();
  TimecardStatusTrack timecardStatus = new TimecardStatusTrack();
  try
  {
              var fEmp = fEmpManager.Where(w =&gt; w.JobId == jobId &amp;&amp;  w.AgencyBiddingProfile.AgencyCandidateId == agencyCandidateId).FirstOrDefault();
              timecard.JobId = jobId;
              timecard.AgencyCandidateId = agencyCandidateId;
              timecard.WeekStartDate = Convert.ToDateTime(weekStartDate,   CultureInfo.InvariantCulture);
              timecard.WeekEndDate = Convert.ToDateTime(weekEndDate, CultureInfo.InvariantCulture);
              timecard.FacilityEmployeeId = fEmp.Id;
              timecard.FacilityId = fEmp.FacilityId;
              timecard.TimecardStatusGCId = timecardStatusDidNotWork;
              timecard.AddUser = SessionManager.AuthorizedInfo.UserId;
              timecard.AddDate = DateTime.Now;
  
              timecardStatus.TimecardStatusGCId = timecardStatusDidNotWork;
              timecardStatus.AddUser = SessionManager.AuthorizedInfo.UserId;
              timecardStatus.AddDate = DateTime.Now;
              timecardStatus.UpdatedBy = SessionManager.AuthorizedInfo.UserId;
              timecardStatus.Comments = string.Empty;
              _ViewTimeCardBusibessService.Create(timecard);
              timecard.TimecardStatusTracks.Add(timecardStatus);
              _ViewTimeCardBusibessService.Update(timecard);
  
          }
          catch (Exception ex)
          {
              HandleValidationErrors(ex);
          }
          finally 
          {
              DependencyContainer.ReleaseInstance(fEmpManager);
          }
  </code></pre>