【问题标题】:To remove records from a list who's column contains elements of the second list using Linq使用 Linq 从列表中删除包含第二个列表元素的记录
【发布时间】:2020-03-16 17:47:05
【问题描述】:

所以我有一个带有值的字符串列表。

List<string> toBeExcluded = new List<string>() { "gmail.com", "yahoo.com" };

我有一个查询,它从数据库中获取了一个列表,其中一列是用户电子邮件。

var user = context.Users.Where(w => !string.IsNullOrEmpty(w.Email));

现在我需要排除那些拥有包含 toBeExcluded 值的电子邮件的用户。所以需要删除域名gmail.com和yahoo.com的所有Email记录。

我试过了,但是没用。

var toBeSent = user.Where(w => !toBeExcluded.Contains(w.Email));    

那我错过了什么?

【问题讨论】:

标签: c# linq


【解决方案1】:

试试这个

var toBeSent = user.Where(w => !toBeExcluded.Any(e => w.Email.EndsWith(e)));    

【讨论】:

    猜你喜欢
    • 2013-06-15
    • 1970-01-01
    • 2019-12-29
    • 1970-01-01
    • 1970-01-01
    • 2021-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多