C# 如何为联合联接和内部查询编写谓词?
我有一个sql语句,必须将其转换为谓词才能传递到方法中C# 如何为联合联接和内部查询编写谓词?,c#,.net,linq,predicate,C#,.net,Linq,Predicate,我有一个sql语句,必须将其转换为谓词才能传递到方法中 select * from applications where IsSuspended = 0 union select * from Applications where id not in (select ApplicationAssociationId from Applications where ApplicationAssociationId is not NULL ) and IsSuspended = 1 我的方法调
select * from applications
where IsSuspended = 0
union
select * from Applications where
id not in
(select ApplicationAssociationId from Applications where ApplicationAssociationId is not NULL )
and IsSuspended = 1
我的方法调用是这样的。我尝试了许多其他的方法,但没有成功(
包含数据的表
预期结果
现在还不清楚你为什么需要一个工会。这不只是一个“或”条件吗
var query = applications.Where(
x => !x.IsSuspended ||
!applications.Any(y => x.Id == y.ApplicationAssociationId));
(在第二种情况下,不需要检查IsSuspended是否为true,就好像它是false一样,它已经包含在第一种情况中。)
var query = applications.Where(
x => !x.IsSuspended ||
!applications.Any(y => x.Id == y.ApplicationAssociationId));