C# 不要在IQueryable中选择特定项目
我有一个关于IQueryable的问题 如何删除/不选择IQueryable中的项目 我的代码返回一个IQueryable,其中包含如下实体列表C# 不要在IQueryable中选择特定项目,c#,C#,我有一个关于IQueryable的问题 如何删除/不选择IQueryable中的项目 我的代码返回一个IQueryable,其中包含如下实体列表 { "ResourceId": "FirstName", "LanguageId": "ENG", "Client": NULL, "ResourceText": "first name x" } { "ResourceId": "FirstName", "LanguageId": "ENG", "Client": 1, "ResourceText":
{
"ResourceId": "FirstName",
"LanguageId": "ENG",
"Client": NULL,
"ResourceText": "first name x"
}
{
"ResourceId": "FirstName",
"LanguageId": "ENG",
"Client": 1,
"ResourceText": "first name y"
}
{
"ResourceId": "LastName",
"LanguageId": "ENG",
"Client": NULL,
"ResourceText": "last name"
}
{
"ResourceId": "BirthDate"
"LanguageId": "ENG"
"Client": NULL
"ResourceText": "date of birth"
}
如果存在一个具有相同ResourceId的特定客户端(非null)的实体,我希望删除客户端==null的实体
对于上述示例,结果应为
{
"ResourceId": "FirstName",
"LanguageId": "ENG",
"Client": 1,
"ResourceText": "first name y"
}
{
"ResourceId": "LastName",
"LanguageId": "ENG",
"Client": NULL,
"ResourceText": "last name"
}
{
"ResourceId": "BirthDate"
"LanguageId": "ENG"
"Client": NULL
"ResourceText": "date of birth"
}
谢谢你的帮助
var result = clients.Where(c => c.Client == null);
其中,
clients
是IQueryable
实体我会这样做:
我们有客户名单客户
。首先,我们要获取所有ResourceID
,其中Client
不为空:
var notNullClients = from c in clients where c.Client != null
select c.ResourceID;
然后您只需使用where
子句过滤您的客户集,如下所示:
var Clients = from c in clients
where ( (c.Client == null & !notNullClients.Contains(c.ResourceID)) |
(c.Client != null & notNullClients.Contains(c.ResourceID)) )
select c;
首先,我们希望将
Client
字段等于null
的客户机设置为只有在没有此类ResourceID
的情况下,才有Client
不为null的客户机。然后,我们使用其余的“NOTNULL clients”。问题还不够清楚,您的意思是在内存列表中有这个,并且您想对它执行linq查询吗?