title: Why does Remove() not delete entities from the database?
body: <p>In trying to figure out how to delete entities from the database in Entity Framework, almost ever hit in google tells me that I need to use Remove(). As in:</p>
  
  <pre><code>ReportComment comment = report.ReportComments.LastOrDefault();
  report.ReportComments.Remove(comment);
  </code></pre>
  
  <p>This is not true. This only orphans the entity. In the case of my ReportComment, it attempts to set the foreign key that points to the Report of which it is a child to null, and this causes the application to crash because the foreign key is set to non-null. They way I had to solve this was as follow:</p>
  
  <p>First create GetContext in my service:</p>
  
  <pre><code>public IRiskAliveContext GetContext()
  {
  return _context;
  }
  </code></pre>
  
  <p>Then I call this function in my controller:</p>
  
  <pre><code>IRiskAliveContext context = _projectService.GetContext();
  </code></pre>
  
  <p>Then I use the context to call Entry() and then set the state of the Entry to Deleted:</p>
  
  <pre><code>ReportComment comment = report.ReportComments.LastOrDefault();
  report.ReportComments.Remove(comment);
  context.Entry(comment).State = EntityState.Deleted;
  </code></pre>
  
  <p>Why do I need to do this? Why does Remove() not work like google says?</p>