title: EntityFramework.Utilities insert all records with a entity reference
body: <p>I'm using EntityFramework.Utilities to insert records on my MVC project.</p>
  
  <p>Here is the website about EntityFramework.Utilities:</p>
  
  <p><a href="https://github.com/MikaelEliasson/EntityFramework.Utilities" rel="nofollow">https://github.com/MikaelEliasson/EntityFramework.Utilities</a></p>
  
  <p>The method that I used is</p>
  
  <pre><code>EFBatchOperation.For(context, context.entityName).InsertAll(listItem);
  </code></pre>
  
  <p>It works and it's fast, however it doesn't allow me to have a entity reference in the listItem, it throw an SQLexception said "Login dailed for user, this session has been assigned a tracing id xxxx-xxxx. It happens when I use the same context to find the BatchTransfer and use the EFBatchOperation to insert the records.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>            try
          {
              //create the context
              ParkingLotContext context = new ParkingLotContext().Sql();
              BatchTransfer batch = context.BatchTransfers.Where(w =&gt; w.Id == pBatch.Id).FirstOrDefault();
              List&lt;UnParsedRecord&gt; unParsedList = new List&lt;UnParsedRecord&gt;();
              foreach (var item in CsvFile.Read&lt;UnParsedRecord&gt;(pUploadPath))
              {
                  item.Id = Guid.NewGuid();
                  item.BatchTransfer = batch;
                  item.ParseState = "UnParsed";
                  unParsedList.Add(item);
              }
  
              EFBatchOperation.For(context, context.UnParsedRecords).InsertAll(unParsedList); //this line throws exception because i'm using the same context
          }
          catch (Exception ex)
          {
              TempData["Message"] = string.Concat("Unable to add batch transfer record into database. ", ex.Message);
              return false;
          }
  </code></pre>
  
  <p>After that, I tried to create a new context just for the insertAll method:</p>
  
  <pre><code>try
          {
              ParkingLotContext context = new ParkingLotContext().Sql();
              EFBatchOperation.For(context, context.UnParsedRecords).InsertAll(unParsedList);
          }
          catch (Exception ex)
  </code></pre>
  
  <p>This time it didn't gave me error but the batchTransfer foreign key(Guid) didn't set(It shows all 0)</p>
  
  <p>How can I fix this or is there a way to get the record by using the EntityFramework.Utilities? Thank you</p>