在LINQ中实现NOT in子句 [英] Implement NOT in clause in LINQ
本文介绍了在LINQ中实现NOT in子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您想要返回当前数据列表中未出现的区域列表;
我有两个数据列表,一个包含一个区域列表;
包含数据的第二个
i想要查询数据列表并仅返回区域列表中不存在
我尝试过:
这是我的代码
Hi want to return a list of areas which dont appear in the current list of data;
I have two list of data, once which contains a list of areas;
A second one which contains the data
i want to query the data list and return only where area does not exist in the list
What I have tried:
This is my code
public static List<string> CheckprocessSubmisson(string department, string searchDate)
{
var itemsnotListed = new List<string>();
var listofProcess = getListofProcesses(department);
var startDate = DateTime.Parse(searchDate).AddHours(7);
var endDate = startDate.AddHours(24);
using (var smpEntities = new SMPEntities())
{
var test1 = (from x in smpEntities.Checks_Records.Where(x => x.DateLogged >= startDate
&& x.DateLogged < endDate
&& x.Checks_Records_Department.Equals(
department))
select x).ToList();
foreach (var item in listofProcess)
{
itemsnotListed = (from x in test1.Where !(from i in x=
}
}
return null;
}
推荐答案
Sir the Demo code given bellow .For the match element Contains but for negative ! operator is used
var exceptionList = new List<string> { "exception1", "exception2" };
var query = myEntities.MyEntity
.Select(e => e.Name)
.Where(e => !exceptionList.Contains(e.Name));
取决于您可能使用的情况:除了(TSource) [ ^ ]或相交(TSource)方法 [ ^ ]或任何(TSource)方法 [ ^ ]
Dependig on situation you may use: Except(TSource)[^] or Intersect(TSource) Method [^] or Any(TSource) Method[^]
试试这可能对你有帮助..
c# - 比较两个列表并使用linq返回不匹配的项目 - Stack Overflow [ ^ ]
try this may be help you..
c# - compare two list and return not matching items using linq - Stack Overflow[^]
这篇关于在LINQ中实现NOT in子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文