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

我正在使用 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 && l.LeadTypeId != 21);

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

10-13 00:26