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.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…