Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6111585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:38:50+00:00 2026-05-23T14:38:50+00:00

I have a 2 classes feeds_Auto and Product with multiple matching properties. For this

  • 0

I have a 2 classes feeds_Auto and Product with multiple matching properties. For this particular problem, the AutoID is the only field I need to use.

I have a List<FeedsAuto> with several hundred unique entries. I have a small List<Product> with 10, 20 unique entries. I now want to remove all items in the small list from the large list.

How do I use RemoveAll({lambda expression}) to accomplish this? All of the examples I have found depend on the generic list being of simple types (strings, ints, etc).

private static int DoInserts(ref List<Model.feeds_Auto> source, ref List<Model.Product> target, Guid companyID)
{
    List<Model.Product> newProductList = new List<Model.Product>();
    List<Model.Product> dropSourceList = new List<Model.Product>();

    using (var db = Helpers.GetProdDB())
    {
        foreach (var src in source)
        {
            var tgt = target.Where(a => a.alternateProductID == src.AutoID && a.LastFeedUpdate < src.DateModified).FirstOrDefault();
            if (tgt == null)
            {
                newProductList.Add(new Model.Product{...});
                dropSourceList.Add(src);
            }
        }
        db.SaveChanges();

        if (dropSourceList.Count > 0)
        {
            source.RemoveAll(????);
        }
    }
}

To do this in a loop is not difficult:

foreach (var drop in dropSourceList)
{
    source.RemoveAll(a => a.AutoID == drop.AutoID);
}

It just does not make sense (to me) to loop on a set to call RemoveAll for one item in each pass.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:38:51+00:00Added an answer on May 23, 2026 at 2:38 pm

    You can use Any to simplify

    source.RemoveAll(a => dropSourceList.Any(b => a.AutoID == b.AutoID));
    

    You can reduce the looping by creating a HashSet of ID’s first:

    var toRemove = new HashSet<int>(dropSourceList.ConvertAll(a => a.AutoID));
    
    source.RemoveAll(a => toRemove.Contains(a.AutoID));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have classes which have automatic properties only like public customerName {get; set;}. They
I have downloaded a third party library and they have classes I need to
I have some classes layed out like this class A { public virtual void
I am using EF4.1, have upgraded my project, generated POCO classes to use DbContext
I have created a class which holds three classes as properties: public class Feeds
I have classes that store data, and methods to go get data for individual
I have classes that are named exactly the same across different plug-ins that I
I have classes that are needed in both my web service and my server.
If I have classes of Type A and B: public class A { public
If I have classes A, B, C, D, E , and interfaces like X,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.