title: Multiple table update in single page handler method razor pages
body: <p>I am getting this error when i am submitting the data</p>
  <blockquote>
  <p>DbUpdateConcurrencyException: Database operation expected to affect 1 row(s) but actually affected 0 row(s). Data may have been modified or deleted since entities were loaded</p>
  </blockquote>
  <p>My Page have more than 50 fields which are inserting into different database.</p>
  <p>this is how i am handling the submit functionality</p>
  <pre><code>public async Task&lt;IActionResult&gt; OnPostSubmitAsync()
          {
              RequestStatus = new SelectList(_context.RequestStatus.OrderBy(e =&gt; e.ID), &quot;RequestStatusValues&quot;, &quot;RequestStatusValues&quot;);
              RequestType = new SelectList(_context.RequestType.OrderBy(e =&gt; e.ID), &quot;ReqType&quot;, &quot;ReqType&quot;);
              Priority = new SelectList(_context.Priority.OrderBy(e =&gt; e.ID), &quot;PriorityValues&quot;, &quot;PriorityValues&quot;);
              
              
              
              Status = new List&lt;SelectListItem&gt; {
                  new SelectListItem { Value = &quot;Yes&quot;, Text = &quot;Yes&quot; },
                  new SelectListItem { Value = &quot;No&quot;, Text = &quot;No&quot; }
              };
              
  
              RequestFormMaster.LastModifiedBy = HttpContext.Session.GetString(&quot;firstname&quot;) + &quot; &quot; + HttpContext.Session.GetString(&quot;lastname&quot;);
              _context.Entry(RequestFormMaster).State = EntityState.Modified;
  
              
  
             
  
              SLAInformation.RequestID = RequestFormMaster.RequestID;
              SLAInformation.SalesDateOfSubmission = DateTime.Now;
              SLAInformation.LastModifiedTimeStamp = DateTime.Now;
              _context.Entry(SLAInformation).State = EntityState.Modified;
  
              
  
              YTDRevenue.RequestID = RequestFormMaster.RequestID;
              YTDRevenue.PricingOwnership = RequestFormMaster.PricingAssignee;
              YTDRevenue.LastModifiedTimeStamp = DateTime.Now;
              _context.Entry(YTDRevenue).State = EntityState.Modified;
  
              ImplementationInfo.RequestID = RequestFormMaster.RequestID;
              ImplementationInfo.CPAID = RequestFormMaster.CPAID;
              ImplementationInfo.LastModifiedTimeStamp = DateTime.Now;
              _context.Entry(ImplementationInfo).State = EntityState.Modified;
  
              //if (LanesRequestingReductionList.Any())
              //{
              //    for (var i = 0; i &lt;= LanesRequestingReductionList.Count(); i++)
              //    {
              //        LanesRequestingReduction.RequestID = RequestFormMaster.RequestID;
              //        LanesRequestingReduction.Counter = i;
              //        _context.Entry(LanesRequestingReduction).State = EntityState.Added;
              //    }
              //}
  
              await _context.SaveChangesAsync();
              TempData[&quot;ReqSubmitted&quot;] = &quot;Submitted&quot;;
              var foldername = RequestFormMaster.RequestID.ToString();
              var DirectoryPath = Path.Combine(_env.WebRootPath, &quot;Documents&quot;, foldername);
              if (!System.IO.Directory.Exists(DirectoryPath))
              {
                  System.IO.Directory.CreateDirectory(DirectoryPath);
              }
              if (ReqSupportingFiles != null || ReqSupportingFiles.Count &gt; 0)
              {
                  int i = 0;
                  foreach (IFormFile upload in ReqSupportingFiles)
                  {
                      i++;
                      // Upload file to server folder
                      string ext = Path.GetExtension(upload.FileName).ToLower();
                      if ((ext == &quot;.ppt&quot;) || (ext == &quot;.pptx&quot;) || (ext == &quot;.xls&quot;) || (ext == &quot;xlsx&quot;))
                      {
                          var filesave = Path.Combine(_env.WebRootPath, &quot;Documents&quot;, foldername, i + &quot;_&quot; + upload.FileName);
                          using (var stream = System.IO.File.Create(filesave))
                          {
                              await upload.CopyToAsync(stream);
                          }
                      }
                  }
              }
              //SendEmailAsync();
              //OnPostUploadFiles(fileData, RequestID);
              return RedirectToPage(&quot;/RequestSummary&quot;);
  
              //return Page();
          }
  </code></pre>
  <p>Is this a correct approach?</p>