gpt4 book ai didi

c# - 从 LINQ 集合中删除项目

转载 作者:行者123 更新时间:2023-11-30 13:15:11 26 4
gpt4 key购买 nike

我想我的问题是正确的:)

我正在使用 LINQ 查询数据库以检索一些数据。请在下面找到代码。

var leadtasktype = _context.LeadTypeTaskTypes.Where(l => l.LeadTypeId == item.Value);

foreach(LeadTypeTaskType l in leadtasktype){
if (l.TaskTypeId == 21)
{
//I need to remove an item which has the tasktype id 21
}
}

正如我在评论中提到的,我需要根据我的 if 条件从 leadtasktype 中删除项目。我该怎么做?

最佳答案

这看起来很像另一个过滤条件:

var leadtasktype = _context.LeadTypeTaskTypes
.Where(l => l.LeadTypeId == item.Value)
.Where(l => l.TaskTypeId != 21); // Exclude ID = 21.

关于c# - 从 LINQ 集合中删除项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13289692/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com