Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 林克!Contains()替换项_C#_Linq - Fatal编程技术网

C# 林克!Contains()替换项

C# 林克!Contains()替换项,c#,linq,C#,Linq,我正在尝试改进使用linq和fluent API的查询的性能 查询如下所示: var result = DbContext.Set<Parent>() .Join(DbContext.Set<Child>(), (parent) => parent.Id, (child) => child.ParentId, (parent,

我正在尝试改进使用linq和fluent API的查询的性能

查询如下所示:

        var result = DbContext.Set<Parent>()
            .Join(DbContext.Set<Child>(),
                (parent) => parent.Id,
                (child) => child.ParentId,
                (parent, child) => cild)
            .Select(x => new { x.SomeOtherId, x.AnotherId })
            .Where(x => !filters.Contains(x.SomeOtherId))
            .Select(x => x.AnotherId )
            .Distinct()
            .ToListAsync(cancellationToken);
这将在有匹配项的情况下给出结果,但是在没有匹配项的情况下如何找到结果


谢谢

“.包含会降低性能”确定吗?你量过了吗?什么是
过滤器
?如果它是一个物化的
列表
或类似的列表,那就可以了。如果它本身是一个查询,那么查询将一次又一次地执行。?“据我所知,.Contains会降低性能”您是否确实对此进行了分析以确保这是您的瓶颈?@JoshuaDunn
!包含
生成一个不在(id1、id2、ide等)中的
SomeOtherId
,其性能取决于
SomeOtherId
是否被索引<代码>包含不会降低性能。缺乏索引确实是一个问题
.Join(filters, (c) => c.SomeOtherId, (filterId) => filterId, (c, filterId) => c.AnotherId);