Query Entities where relation is empty

Posts   
 
    
tmatelich
User
Posts: 95
Joined: 14-Oct-2009
# Posted on: 14-Jun-2011 13:43:29   

Using v2.6 - latest

I have a relation ReportEntry - Disposition (1:n). I want to query for ReportEntryEntities which have n == 0 using adapter.FetchTypedList. Is that possible?

Thanks!

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 14-Jun-2011 15:06:53   

You will have to do something like:

WHERE ID NOT IN (SELECT ReportId FROM Disposition).

And for this you need to use a FieldcompareSetPredicate with the negate parameter set to true.

tmatelich
User
Posts: 95
Joined: 14-Oct-2009
# Posted on: 14-Jun-2011 15:31:51   

Like this?


var undisposed = new FieldCompareSetPredicate(ReportEntryFields.ReportEntryId, null, DispositionFields.ReportEntryId, null, SetOperator.In, null) { Negate = true };
filter.PredicateExpression.Add(undisposed);

I have a number of other predicates on ReportEntryFields as well. Is it advantageous to move those into the FieldCompareSetPredicate?

e.g.


filter.PredicateExpression.Add(ReportEntryFields.Deleted == false);

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 14-Jun-2011 21:04:10   

That looks like it should do the trick. I don't think there is any advantage in moving them into the FieldCompareSet predicate unless they need to be there.

Matt

tmatelich
User
Posts: 95
Joined: 14-Oct-2009
# Posted on: 23-Jun-2011 00:25:49   

Thanks for your help!