I have a sql statement and I have to convert it into predicate to pass into a method.
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
my method call is like this. I tried many other way but not get success. :(
var resultList = someinstance.GetAll(
app=> app.IsSuspended = false)
.Union(someinstance.GetAll(
xap=>!xap.Id.Contains((xap.ApplicationAssociationId !=null).select(xap.Id)))
).ToList();
Table Containing Data
Expected Result
It's not clear why you need a union at all here. Isn't it just an "or" condition?
var query = applications.Where(
x => !x.IsSuspended ||
!applications.Any(y => x.Id == y.ApplicationAssociationId));
(There's no need to check for IsSuspended being true in the second case, as if it's false it'll already be included in the first case.)
See more on this question at Stackoverflow