EXCEPT 运算符是否可以排除列包含数组中的数据的数据

本文关键字:数据 包含 数组 排除 运算符 是否 EXCEPT | 更新日期: 2023-09-27 18:35:26

>假设有一个逗号分隔的文本值字符串,就像一个数组:

var excludelist ="apples,oranges,grapes,pears";

排除列表值可能来自对数据库中表的查询。

假设一个查询,其中我们希望返回所有行,除了名为 Fruit 的字段包含排除列表中任何项目的那些行。

var qry = from s in context.Groceries.Where(s => s.Fruit(here is where we need to exclude the items??) join u in context.Users on s.Owner equals u.User_ID

有人可以提供指向 SQL 答案的示例链接吗?

EXCEPT 运算符是否可以排除列包含数组中的数据的数据

你试过Except吗?

var qry = from s in context.Groceries.Except(excludelist)...

链接到 SQL 已CONTAINS(和!包含)

where !excludelist.Contains(i)
        select i;

我是这样解决的:

有一个数据库表,其中包含我希望排除的水果的名称,并且我创建了一个列表(IList 显然不起作用)。

List<string> excludedfruit = context.ExcludedFruit.Select(x => x.ExcludedFruitName).ToList();

然后我使用了以下 Linq to SQL 查询(部分显示)

        var qry = from s in context.Groceries
                .Where(s => !excludedfruit.Contains(s.Fruit))