title: Entity Framework dbset most efficient way of deleting
body: <p>I have the following and looking for a more  efficient way of deleting vs looping through the records and then deleting each one at a time (note using Dbset):</p>
  
  <pre><code>     var wcd = dbContext.ProgramDetails.Where(p =&gt; p.Id == Id);
  
       foreach (var wc in wcd.ToList())
       {
          dbContext.ProgramDetails.Remove(wc);
       }
  
       dbContext.SaveChanges();
  </code></pre>
  
  <p>Also say if we have 1 record that is as following:</p>
  
  <pre><code>    var pg = dbContext.Program.Where(p =&gt; p.Id == Id &amp;&amp; Name == FName);
  </code></pre>
  
  <p>What is the best way of deleting this one record? </p>
  
  <p>tried the following but gave an error: </p>
  
  <pre><code>    var pg = dbContext.Program.Where(p =&gt; p.Id == Id &amp;&amp; Name == FName);
      dbContext.Program.Remove(wc);
  </code></pre>
  
  <p>Then I resorted to doing a foreach for deleting just one record as I have shown above that is not the most efficient for just 1 record.</p>