当不同类型的List的属性值相等时,Linq查询要从List中排除? [英] Linq query to exclude from a List when a property value of List of different type are equal?

查看:153
本文介绍了当不同类型的List的属性值相等时,Linq查询要从List中排除?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类型为Fee的列表,我需要从中排除具有另一个int类型的List中存在的ID的列表.

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();

示例: 列出GoodFees =(从ctx.Fees中的f,其中f.FeeID!= ExcludedFeeID中的ID之一);

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

请帮助?

推荐答案

尝试一下:

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

这篇关于当不同类型的List的属性值相等时,Linq查询要从List中排除?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆