Linq query to exclude from a List when a property value of List of different type are equal?

11,912

Try this:

var MyFees = from c in ctx.Fees
             where !ExcludedFeeIDs.Contains(c.FeeID)
             select c;
Share:
11,912

Related videos on Youtube

Ozzie Perez
Author by

Ozzie Perez

Updated on April 17, 2022

Comments

  • Ozzie Perez
    Ozzie Perez about 2 years

    I have a List of type Fee from which I need to exclude the ones that have an ID that exists in another List of type int.

    List<int> ExcludedFeeIDs = new List<int>{1,2,3,4};
    
    List<Fee> MyFees = (from c in ctx.Fees
                        select c).ToList();
    

    Example: List GoodFees = (from f in ctx.Fees where f.FeeID!=One of the IDs in ExcludedFeeIDs);

    Help please?

  • Ozzie Perez
    Ozzie Perez over 14 years
    Worked like a charm! Thanks Yannick.
  • ICR
    ICR over 14 years
    For simply queries some people prefer using the dot notation: var myFees = ctx.Fees.Where(fee => !ExcludedFeeIDs.Contains(fee.FeeID));