title: Update entity framework entity with multiple relationships to other entities
body: <p>I am using web api with entity framework core. I have a Worker entity with relationships to Company (via CompanyId),  Status (via StatusId) and Position (via PositionId). Using a request through the API I want to be able to update a worker. </p>
  
  <p>I want to pass a request of WorkerId and PositionId only. In the data layer I check to find the PositiionId exists from the request, if not the return back to the controller with message of Position not found. Below is a sample of the code without the Company and Status checks.</p>
  
  <pre><code>Public void Update(WorkerEntity worker)
  {
      var workerRecord = _context.WorkerEntity.SingleOrDefault(w =&gt; w.Id == worker.Id);
  
      if (workerRecord == null)
      {
           Log.Logger("Cannot find the worker with Id " + worker.Id);
           return;
      }
  
      var positionRecord = _context.PositionEntity.SingleOrDefault(w =&gt; w.Id == worker.PositionId);
  
      if (positionRecord == null)
      {
           Log.Logger("Cannot find the position with Id " + worker.PositionId);
           return;
      }
  
      workerRecord.Position = positionRecord;
      _context.SaveChanges();
  }
  </code></pre>
  
  <p>I have also tried a simple approach using <strong>.Single</strong> to catch an error if the record does exist but the catch only output the generic "Sequence contains no elements" which isn't helpful in knowing with entity failed.</p>
  
  <p>Is there an easier way to check the relationship Ids the user has added in the request are not bogus without having lines and code checking the Id exists? This table may have 3 relationships but I have another table that has 5 which would have 5 if null checks.</p>