Hi LLBLGen,
I'm trying to create the following query:
SELECT COUNT(*) AS NumberOfLinks
FROM Links
WHERE SourceIncidentId = 4 OR TargetIncidentId = 4
HAVING COUNT(*) > 2
But can't seem to produce a having clause without a group by field.
It turns the having clause in a where clause but that is not the same
I currently have this:
EntityField2 countField = LinkFields.LinkId.SetAggregateFunction(AggregateFunction.CountRow);
EntityFields2 fields = new EntityFields2(1) { countField };
RelationPredicateBucket bucket = new RelationPredicateBucket(LinkFields.SourceIncidentId == 4 | LinkFields.TargetIncidentId == 4);
GroupByCollection groupBy = new GroupByCollection();
groupBy.HavingClause = new PredicateExpression(countField > 2);
DataTable table = new DataTable();
this.AdapterToUse.FetchTypedList(fields, table, bucket, 0, null, true, groupBy);
But this generates the following sql:
SELECT COUNT(*) AS LinkId
FROM Links
WHERE SourceIncidentId = 200 OR TargetIncidentId = 200
So i'm missing my having clause with the count