title: Excluding items using linq
body: <p>I have two lists being returned via LINQ. My goal is to return all the items from the 'defaults' list minus what is in the 'notDefaults' list.</p>
  
  <p>I'm currently doing this via two nested for loops and using 'RemoveAt'. Could this be done with only one LINQ statement? Basically, I need everything in the 'defaults' list unless the item exists in the table 'AssetPayrollMarkupOverrides'.</p>
  
  <p>I'm apprehensive about using 'RemoveAt' since <a href="https://stackoverflow.com/questions/6926554/how-to-quickly-remove-items-from-a-list">it appears to be slow</a>.</p>
  
  <pre><code>var defaults = (from a in dbcontext.Assets
      join b in dbcontext.AssetAddresses on a.AssetID equals b.AssetID
      join c in dbcontext.Addresses on b.AddressID equals c.AddressID
      join d in dbcontext.StateLookups on c.StateID equals d.StateID
      where d.ShortName == state
      select new AssetMarkup()
      {
          AssetId = a.AssetID,
          AssetName = a.AssetName,
          Seg1_Code = a.Seg1_Code,
      }).ToList();
  
  
  var notDefaults = (from a in dbcontext.Assets
      join b in dbcontext.AssetAddresses on a.AssetID equals b.AssetID
      join c in dbcontext.Addresses on b.AddressID equals c.AddressID
      join d in dbcontext.StateLookups on c.StateID equals d.StateID
      join e in dbcontext.AssetPayrollMarkupOverrides on a.AssetID equals e.AssetID
      where d.ShortName == state
      select new AssetMarkup()
      {
          AssetId = a.AssetID,
          AssetName = a.AssetName,
          Seg1_Code = a.Seg1_Code,
          ShortName = d.ShortName,
          OfficePercentage = e.OfficePercentage,
          MaintenancePercentage = e.MaintenancePercentage,
          Note = e.Note
      }).ToList();
  </code></pre>
  
  <p>I originally had it this way to make sure the two lists matched:</p>
  
  <pre><code>var defaults = (from a in dbcontext.Assets
      join b in dbcontext.AssetAddresses on a.AssetID equals b.AssetID
      join c in dbcontext.Addresses on b.AddressID equals c.AddressID
      join d in dbcontext.StateLookups on c.StateID equals d.StateID
      where d.ShortName == state
      select new AssetMarkup()
      {
          AssetId = a.AssetID,
          AssetName = a.AssetName,
          Seg1_Code = a.Seg1_Code,
          ShortName = d.ShortName,
          OfficePercentage = dbcontext.PayrollMarkups.Where(x =&gt; x.StateID == c.StateID).Select(x =&gt; x.OfficePercentage).FirstOrDefault(),
          MaintenancePercentage = dbcontext.PayrollMarkups.Where(x =&gt; x.StateID == c.StateID).Select(x =&gt; x.MaintenancePercentage).FirstOrDefault(),
          Note = dbcontext.AssetPayrollMarkupOverrides.Where(x =&gt; x.AssetID == a.AssetID).Select(x =&gt; x.Note).FirstOrDefault()
      }).ToList();
  
  var notDefaults = (from a in dbcontext.Assets
     join b in dbcontext.AssetAddresses on a.AssetID equals b.AssetID
     join c in dbcontext.Addresses on b.AddressID equals c.AddressID
     join d in dbcontext.StateLookups on c.StateID equals d.StateID
     join e in dbcontext.AssetPayrollMarkupOverrides on a.AssetID equals e.AssetID
     where d.ShortName == state
     select new AssetMarkup()
     {
         AssetId = a.AssetID,
         AssetName = a.AssetName,
         Seg1_Code = a.Seg1_Code,
         ShortName = d.ShortName,
         OfficePercentage = dbcontext.PayrollMarkups.Where(x =&gt; x.StateID == c.StateID).Select(x =&gt; x.OfficePercentage).FirstOrDefault(),
         MaintenancePercentage = dbcontext.PayrollMarkups.Where(x =&gt; x.StateID == c.StateID).Select(x =&gt; x.MaintenancePercentage).FirstOrDefault(),
         Note = dbcontext.AssetPayrollMarkupOverrides.Where(x =&gt; x.AssetID == a.AssetID).Select(x =&gt; x.Note).FirstOrDefault()
     }).ToList();
  
  return Json(defaults.Except(notDefaults).OrderBy(x =&gt; x.AssetName).ToDataSourceResult(request));
  </code></pre>