I just added the following block to an existing set of query code. I'm tacking on a subquery to an existing TypedList. One of the tables in the subquery is already in the TypedList, so I'm aliasing it. Here's my code....
// other code happens above to set up rest of query
// we fall into following block if we are trying to see properties by tags
{
/**
* Here we are trying to add the following sub query from the main typed list
...AND Property.PropertyID IN (
SELECT Property2.PropertyID from
Property AS Property2
inner join PropertyTag pt
on Property2.PropertyID = pt.PropertyID
inner join Tag t
on pt.TagID = t.TagID
WHERE
t.Tag IN (<tag list>)
GROUP BY Property2.PropertyID
HAVING COUNT(Property2.PropertyID) = <# of tags>
**/
// Here's our inner joins
RelationCollection relations = new RelationCollection();
relations.Add(PropertyEntity.Relations.PropertyTagEntityUsingPropertyID, "Property2", null, JoinHint.Inner);
relations.Add(PropertyTagEntity.Relations.TagEntityUsingTagID);
// Here's our WHERE t.Tag in clause
IPredicateExpression subqueryWhere = new PredicateExpression();
subqueryWhere.Add(PredicateFactory.CompareRange(TagFieldIndex.Tag, query.Tags.ToArray()));
// Here's our group by with the having count = <# of tags>
IGroupByCollection groupBy = new GroupByCollection();
groupBy.Add(EntityFieldFactory.Create(PropertyFieldIndex.PropertyID));
FieldCompareValuePredicate havingFilter = PredicateFactory.CompareValue(PropertyFieldIndex.PropertyID, ComparisonOperator.Equal, query.Tags.Count);
havingFilter.FieldCore.AggregateFunctionToApply = AggregateFunction.Count;
groupBy.HavingClause = new PredicateExpression(havingFilter);
// Finally, we add the subquery
bucket.PredicateExpression.AddWithAnd(new FieldCompareSetPredicate(
EntityFieldFactory.Create(PropertyFieldIndex.PropertyID), null,
EntityFieldFactory.Create(PropertyFieldIndex.PropertyID), null,
SetOperator.In, subqueryWhere, relations, "Property2", 0, null, false, groupBy));
When I try to execute this block I'm getting a NullReferenceException thrown by the DynamicQueryEngine.CreateRowCountDQ method in my generated Adapter class. It seems that it's happening on down in the ORMSupportClasses.RelationCollection.ToQueryText method. Here's the pertinent part of the stack trace.
SD.LLBLGen.Pro.ORMSupportClasses.RelationCollection.ToQueryText(Int32& uniqueMarker) +551
SD.LLBLGen.Pro.DQE.SqlServer.DynamicQueryEngine.CreateSelectDQ(IEntityFieldCore[] selectList, IFieldPersistenceInfo[] fieldsPersistenceInfo, IDbConnection connectionToUse, IPredicate selectFilter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relationsToWalk, Boolean allowDuplicates, IGroupByCollection groupByClause, Int32& uniqueMarker) +1460
SD.LLBLGen.Pro.DQE.SqlServer.SqlServerSpecificCreator.CreateSubQuery(IEntityFieldCore[] selectList, IFieldPersistenceInfo[] fieldPersistenceInfos, IPredicate selectFilter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relationsToWalk, IGroupByCollection groupByClause, Int32& uniqueMarker) +104
SD.LLBLGen.Pro.ORMSupportClasses.FieldCompareSetPredicate.ToQueryText(Int32& uniqueMarker, Boolean inHavingClause) +245
SD.LLBLGen.Pro.ORMSupportClasses.PredicateExpression.ToQueryText(Int32& uniqueMarker, Boolean inHavingClause) +404
SD.LLBLGen.Pro.ORMSupportClasses.PredicateExpression.ToQueryText(Int32& uniqueMarker) +6
SD.LLBLGen.Pro.DQE.SqlServer.DynamicQueryEngine.CreateSelectDQ(IEntityFieldCore[] selectList, IFieldPersistenceInfo[] fieldsPersistenceInfo, IDbConnection connectionToUse, IPredicate selectFilter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relationsToWalk, Boolean allowDuplicates, IGroupByCollection groupByClause, Int32& uniqueMarker) +1870
SD.LLBLGen.Pro.DQE.SqlServer.DynamicQueryEngine.CreateRowCountDQ(IEntityFieldCore[] selectList, IFieldPersistenceInfo[] fieldsPersistenceInfo, IDbConnection connectionToUse, IPredicate selectFilter, IRelationCollection relationsToWalk, Boolean allowDuplicates, IGroupByCollection groupByClause) +93
Any ideas? This is 1.2004.2 with Adapter. Thanks!