If I have this code:
Predicate documentFilter = ShipFields.ID == DocumentTransactionFields.ShipID &
DocumentTransactionFields.VoyageID == DBNull.Value &
DocumentTransactionFields.AllocatedFlag == true;
ScalarQueryExpression followUpMessagesQuery =
new ScalarQueryExpression(
DocumentFields.ID.SetAggregateFunction(AggregateFunction.Count),
documentFilter & DocumentFields.FollowUpFlag == true, relations);
ScalarQueryExpression hasPriorityMessagesQuery =
new ScalarQueryExpression(
DocumentFields.ID.SetAggregateFunction(AggregateFunction.Count),
documentFilter & DocumentFields.PriorityFlag == true, relations);
I am performing almost the same query twice.
Looking back in the forums, I see that Derived Tables were mentioned some time ago but I can't find anything current. Am I right in thinking this would be a candidate for a Derived Table so I can retrieve two pieces of information from one query?
Secondly, the second expression currently returns an aggregate Count but I actually only need to know if any matching rows are present. Seems a waste to count all the documents (there might be a lot) when ideally I would like it to short-circuit on finding one. This might be more of a SQL question but what is the best way of doing this?
Cheers
Simon