【问题标题】:Linq query to exclude from a List when a property value of List of different type are equal?当不同类型的列表的属性值相等时,Linq 查询从列表中排除?
【发布时间】:2009-09-18 17:23:32
【问题描述】:

我有一个费用类型的列表,我需要从中排除 ID 存在于另一个 int 类型列表中的列表。

List<int> ExcludedFeeIDs = new List<int>{1,2,3,4};

List<Fee> MyFees = (from c in ctx.Fees
                    select c).ToList();

示例: List GoodFees = (from f in ctx.Fees where f.FeeID!=ExcludedFeeIDs 中的ID之一);

请帮忙?

【问题讨论】:

    标签: c# linq join


    【解决方案1】:

    试试这个:

    var MyFees = from c in ctx.Fees
                 where !ExcludedFeeIDs.Contains(c.FeeID)
                 select c;
    

    【讨论】:

    • 工作就像一个魅力!谢谢雅尼克。
    • 对于一些人喜欢使用点符号的简单查询:var myFees = ctx.Fees.Where(fee => !ExcludedFeeIDs.Contains(fee.FeeID));
    猜你喜欢
    • 1970-01-01
    • 2021-05-10
    • 1970-01-01
    • 2020-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多