title: ASP.NET Core multiple file upload, SQL Server identity column Issue
body: <p>I've an issue with multiple file upload in ASP.NET Core. When I'm uploading multiple files at once, I'm getting this error from the SQL Server database :</p>
  
  <blockquote>
    <p>SqlException: Cannot insert explicit value for identity column in table 'photos' when IDENTITY_INSERT is set to OFF.</p>
  </blockquote>
  
  <p>My code: </p>
  
  <pre><code>    public async Task&lt;IActionResult&gt; Create(Photos photos)
      {
          if (ModelState.IsValid)
          {
              var date = DateTime.UtcNow.AddHours(4);
              var photoAddDate = photos.PhotoAddedData = date.ToString("yyyy- 
              MM-dd','HH:mm:ss", CultureInfo.InvariantCulture);
  
              foreach (var file in photos.FormFile)
              {
                  var filePath = Path.Combine(_hostingEnvironment.WebRootPath, 
                  Path.GetFileName(file.FileName));
                  photos.PhotoPath = "/" + Path.GetFileName(file.FileName);
                  var stream = new FileStream(filePath, FileMode.Create);
                  await file.CopyToAsync(stream);
                  photos.PhotoPath = filePath;
                  _context.Photos.Add(photos);
                  await _context.SaveChangesAsync();
              }
  
              return RedirectToAction(nameof(Index));
        }
  </code></pre>
  
  <p>I then tried with this code :</p>
  
  <pre><code>var transaction = _context.Database.BeginTransaction();
  _context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT[dbo].[photos]ON;");
  _context.Photos.Add(photos);
  await _context.SaveChangesAsync();
  _context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT[dbo].[photos] OFF;");
  transaction.Commit();
  </code></pre>
  
  <p>and got another error :</p>
  
  <blockquote>
    <p>SqlException: Explicit value must be specified for identity column in table 'photos' either when IDENTITY_INSERT is set to ON or when a replication user is inserting into a NOT FOR REPLICATION identity column.</p>
  </blockquote>
  
  <p>Can anyone help me with this? Thank you very much</p>