NullReferenceException in subquery

Posts   
 
    
werdage
User
Posts: 3
Joined: 28-Feb-2006
# Posted on: 28-Feb-2006 08:31:40   

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!

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39930
Joined: 17-Aug-2003
# Posted on: 28-Feb-2006 08:44:13   

You're using the latest 1.0.2004.2 runtime builds?

Frans Bouma | Lead developer LLBLGen Pro
werdage
User
Posts: 3
Joined: 28-Feb-2006
# Posted on: 28-Feb-2006 08:48:37   

I think so. I'm using 1.0.20042.50803 if that's the latest.

Edit: Check that, I just downloaded the latest version of the 1.2004.2 runtime libraries from 1/3/06, and still the same problem.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39930
Joined: 17-Aug-2003
# Posted on: 28-Feb-2006 09:28:14   

instead of: relations.Add(PropertyEntity.Relations.PropertyTagEntityUsingPropertyID, "Property2", null, JoinHint.Inner); do: relations.Add(PropertyEntity.Relations.PropertyTagEntityUsingPropertyID, "Property2", string.Empty, JoinHint.Inner);

Don't use 'null' for string types, use string.Empty, then you'll never run into these issues again simple_smile

Frans Bouma | Lead developer LLBLGen Pro
werdage
User
Posts: 3
Joined: 28-Feb-2006
# Posted on: 28-Feb-2006 15:01:09   

flushed Heh. Ooops.

This did the trick. Thanks for the help, Otis. You guys are great.