Hello. I'm having trouble coming up with the right predicates expression for my Where clause. I want to emulate this query (notice the parens)....
SELECT * FROM News
WHERE ((PublishingStatusId = 1) AND (PendingNewsId is null) OR (PublishingStatusId = 2))
AND NewsDate = 1/1/2005
I want the "NewsDate" Section to not be part of the AND or OR. this is my code which is not working right.
// published and no pending
expPub.Add(PredicateFactory.CompareValue(NewsFieldIndex.PublishingStatusId, ComparisonOperator.Equal, (int) PublishingStatus.Published));
expPub.AddWithAnd(PredicateFactory.CompareNull(NewsFieldIndex.PendingNewsId));
bucket.PredicateExpression.Add(expPub);
// all pending
expPend.Add(PredicateFactory.CompareValue(NewsFieldIndex.PublishingStatusId, ComparisonOperator.Equal, (int) PublishingStatus.Working));
bucket.PredicateExpression.AddWithOr(expPend);
// by date
expDate.Add(PredicateFactory.CompareValue(NewsFieldIndex.NewsDate, ComparisonOperator.Equal, newsDate.Date));
bucket.PredicateExpression.Add(expDate);
adapter.FetchEntityCollection(ec, bucket, 0, new SortExpression(SortClauseFactory.Create(NewsFieldIndex.UpdatedDate, SortOperator.Descending)));
this is generating the following SQL (notice the parens):
SELECT * FROM [News]
WHERE (([PublishingStatusId] = 1 And [PendingNewsId] IS NULL) Or ([PublishingStatusId] = 2)
And ( [NewsDate] = 'Apr 26 2005 12:00:00:000AM'))