newbie dbfunctioncall question

Posts   
 
    
pmdegoede
User
Posts: 3
Joined: 19-Nov-2009
# Posted on: 19-Nov-2009 09:15:32   

Hi,

This should be quite simple but I'm struggling. I want to perform the following query in postgres (using postgis), LLBLGen v2.6, adapter, std templates.

select * from "Thing" where ST_Intersects("LocationGeom", 'POINT (1 2)') = TRUE

The 1st attempt was: DataAccessAdapter adapter = new DataAccessAdapter(); EntityCollection things = new EntityCollection(new ThingEntityFactory()); DbFunctionCall ST_Intersects = new DbFunctionCall("ST_Intersects", new object[] { ThingFields.LocationGeom, wkt}); IPredicate SpatialFilter = new EntityField("Intersects", ST_Intersects) == true; IRelationPredicateBucket bucket = new RelationPredicateBucket(); bucket.PredicateExpression.Add(SpatialFilter); adapter.FetchEntityCollection(things, bucket);

And the 2nd attempt was: DataAccessAdapter adapter = new DataAccessAdapter(); EntityCollection things = new EntityCollection(new ThingEntityFactory()); DbFunctionCall ST_Intersects = new DbFunctionCall("ST_Intersects({0},{1})", new object[] { ThingFields.LocationGeom, wkt}); IPredicate SpatialFilter = new EntityField("Intersects", ST_Intersects) == true; IRelationPredicateBucket bucket = new RelationPredicateBucket(); bucket.PredicateExpression.Add(SpatialFilter); adapter.FetchEntityCollection(things, bucket);

3rd attempt: DataAccessAdapter adapter = new DataAccessAdapter(); EntityCollection things = new EntityCollection(new ThingEntityFactory()); DbFunctionCall ST_Intersects = new DbFunctionCall("ST_Intersects({0},{1})", new object[] { ThingFields.LocationGeom, wkt }); EntityField fieldWithSubString = new EntityField("SkuSubstring", ST_Intersects); IRelationPredicateBucket bucket = new RelationPredicateBucket(); bucket.PredicateExpression.Add(fieldWithSubString == true); adapter.FetchEntityCollection(things, bucket);

Does anyone have an idea what basic thing I'm missing? I always get a nullref exception when it's trying to build the query: at SD.LLBLGen.Pro.DQE.PostgreSql.PostgreSqlSpecificCreator.CreateObjectName(IFieldPersistenceInfo persistenceInfo) at SD.LLBLGen.Pro.DQE.PostgreSql.PostgreSqlSpecificCreator.CreateFieldName(IFieldPersistenceInfo persistenceInfo, String fieldName, String objectAlias, Boolean appendAlias, String containingObjectName, String actualContainingObjectName) at SD.LLBLGen.Pro.ORMSupportClasses.DbSpecificCreatorBase.ConvertFieldToRawName(IEntityFieldCore fieldCore, IFieldPersistenceInfo persistenceInfo, String fieldName, String objectAlias, Int32& uniqueMarker, Boolean applyAggregateFunction) at SD.LLBLGen.Pro.DQE.PostgreSql.PostgreSqlSpecificCreator.CreateFieldName(IEntityFieldCore fieldCore, IFieldPersistenceInfo persistenceInfo, String fieldName, String objectAlias, Int32& uniqueMarker, Boolean applyAggregateFunction) at SD.LLBLGen.Pro.ORMSupportClasses.DbFunctionCall.CreateParameterFragments(Int32& uniqueMarker, Boolean inHavingClause) at SD.LLBLGen.Pro.ORMSupportClasses.DbFunctionCall.ToQueryText(Int32& uniqueMarker, Boolean inHavingClause) at SD.LLBLGen.Pro.ORMSupportClasses.DbFunctionCall.SD.LLBLGen.Pro.ORMSupportClasses.IExpression.ToQueryText(Int32& uniqueMarker, Boolean inHavingClause) at SD.LLBLGen.Pro.ORMSupportClasses.DbSpecificCreatorBase.ConvertFieldToRawName(IEntityFieldCore fieldCore, IFieldPersistenceInfo persistenceInfo, String fieldName, String objectAlias, Int32& uniqueMarker, Boolean applyAggregateFunction) at SD.LLBLGen.Pro.DQE.PostgreSql.PostgreSqlSpecificCreator.CreateFieldName(IEntityFieldCore fieldCore, IFieldPersistenceInfo persistenceInfo, String fieldName, String objectAlias, Int32& uniqueMarker, Boolean applyAggregateFunction) at SD.LLBLGen.Pro.ORMSupportClasses.FieldCompareValuePredicate.ToQueryText(Int32& uniqueMarker, Boolean inHavingClause) at SD.LLBLGen.Pro.ORMSupportClasses.PredicateExpression.ToQueryText(Int32& uniqueMarker, Boolean inHavingClause) at SD.LLBLGen.Pro.ORMSupportClasses.PredicateExpression.ToQueryText(Int32& uniqueMarker, Boolean inHavingClause) at SD.LLBLGen.Pro.ORMSupportClasses.PredicateExpression.ToQueryText(Int32& uniqueMarker) at SD.LLBLGen.Pro.DQE.PostgreSql.DynamicQueryEngine.CreateSelectDQ(IEntityFieldCore[] selectList, IFieldPersistenceInfo[] fieldsPersistenceInfo, IDbConnection connectionToUse, IPredicate selectFilter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relationsToWalk, Boolean allowDuplicates, IGroupByCollection groupByClause, Boolean relationsSpecified, Boolean sortClausesSpecified)

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 19-Nov-2009 10:22:10   

select * from "Thing" where ST_Intersects("LocationGeom", 'POINT (1 2)') = TRUE

4th attempt:

            DataAccessAdapter adapter = new DataAccessAdapter();
            EntityCollection things = new EntityCollection(new ThingEntityFactory());

            DbFunctionCall ST_Intersects = new DbFunctionCall("ST_Intersects({0},{1})", new object[] { ThingFields.LocationGeom, wkt});

            IEntityField2 field = ThingFields.LocationGeom.SetExpression(ST_Intersects);

            IPredicateExpression SpatialFilter = new PredicateExpression (field == true);
            IRelationPredicateBucket bucket = new RelationPredicateBucket();
            bucket.PredicateExpression.Add(SpatialFilter);

            adapter.FetchEntityCollection(things, bucket);
pmdegoede
User
Posts: 3
Joined: 19-Nov-2009
# Posted on: 19-Nov-2009 12:04:26   

Thanks. I couldn't compile though. Error on line: IPredicateExpression SpatialFilter = new PredicateExpression(field == true);

error CS0019: Operator '==' cannot be applied to operands of type 'SD.LLBLGen.Pro.ORMSupportClasses.IEntityField2' and 'bool'

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 19-Nov-2009 12:26:36   

Sorry about that, me bad.

Instead of this:

IEntityField2 field = ThingFields.LocationGeom.SetExpression(ST_Intersects);

use:

EntityField2 field = ThingFields.LocationGeom.SetExpression(ST_Intersects);