DB functioncall as predicateexpression

Posts   
 
    
Jamanga
User
Posts: 93
Joined: 21-Jul-2006
# Posted on: 28-Oct-2011 09:34:16   

Hi all

I am running LLBLGen 2.6 Final (runtime 2.6.11.0427) via VS2008 on Windows XP. The data is hosted on Sybase ASE.

I am trying to fetch entities that have a length greater than 12 characters via the following code, however this results in an "Object reference not set to an instance of an object." during the .Fetch call.

What am I doing wrong?

using (var skuDetails = new ProductEntities()) {
    RelationPredicateBucket filter = new RelationPredicateBucket(ProductFields.Skn == thisSkn.Skn);
    EntityField fieldSkuLength = new EntityField("SkuLength", new DbFunctionCall("LEN({0})", new object[] { ProductFields.Sku }));
    filter.PredicateExpression.Add(fieldSkuLength >= 12);
    var sorter = new SortExpression(ProductFields.Sku | SortOperator.Ascending);                                        
    adapter.FetchEntityCollection(skuDetails, filter, 0, sorter);
    // processing..
}
Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 28-Oct-2011 10:30:24   

Please post the stack trace.

Jamanga
User
Posts: 93
Joined: 21-Jul-2006
# Posted on: 29-Oct-2011 00:00:16   

Hi Walaa

Stack Trace:

"   at SD.LLBLGen.Pro.DQE.SybaseAse.SybaseAseSpecificCreator.CreateObjectName(IFieldPersistenceInfo persistenceInfo)
   at SD.LLBLGen.Pro.DQE.SybaseAse.SybaseAseSpecificCreator.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.SybaseAse.SybaseAseSpecificCreator.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.SybaseAse.SybaseAseSpecificCreator.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.SybaseAse.DynamicQueryEngine.CreateSelectDQ(IEntityFieldCore[] selectList, IFieldPersistenceInfo[] fieldsPersistenceInfo, IDbConnection connectionToUse, IPredicate selectFilter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relationsToWalk, Boolean allowDuplicates, IGroupByCollection groupByClause, Boolean relationsSpecified, Boolean sortClausesSpecified)
   at SD.LLBLGen.Pro.ORMSupportClasses.DynamicQueryEngineBase.CreateSelectDQ(IEntityFieldCore[] selectList, IFieldPersistenceInfo[] fieldsPersistenceInfo, IDbConnection connectionToUse, IPredicate selectFilter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relationsToWalk, Boolean allowDuplicates, IGroupByCollection groupByClause)
   at SD.LLBLGen.Pro.DQE.SybaseAse.DynamicQueryEngine.CreatePagingSelectDQ(IEntityFieldCore[] selectList, IFieldPersistenceInfo[] fieldsPersistenceInfo, IDbConnection connectionToUse, IPredicate selectFilter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relationsToWalk, Boolean allowDuplicates, IGroupByCollection groupByClause, Int32 pageNumber, Int32 pageSize)
   at SD.LLBLGen.Pro.ORMSupportClasses.DynamicQueryEngineBase.CreateSelectDQ(IEntityFieldCore[] selectList, IFieldPersistenceInfo[] fieldsPersistenceInfo, IDbConnection connectionToUse, IPredicate selectFilter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relationsToWalk, Boolean allowDuplicates, IGroupByCollection groupByClause, Int32 pageNumber, Int32 pageSize)
   at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.CreateSelectDQ(IEntityFields2 fieldsToFetch, IFieldPersistenceInfo[] persistenceInfoObjects, IPredicateExpression filter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relationsToWalk, Boolean allowDuplicates, IGroupByCollection groupByClause, Int32 pageNumber, Int32 pageSize)
   at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchEntityCollectionInternal(IEntityCollection2 collectionToFill, IRelationPredicateBucket& filterBucket, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, ExcludeIncludeFieldsList excludedIncludedFields, Int32 pageNumber, Int32 pageSize)
   at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchEntityCollection(IEntityCollection2 collectionToFill, IRelationPredicateBucket filterBucket, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, IPrefetchPath2 prefetchPath, ExcludeIncludeFieldsList excludedIncludedFields, Int32 pageNumber, Int32 pageSize)
   at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchEntityCollection(IEntityCollection2 collectionToFill, IRelationPredicateBucket filterBucket, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses)
   at OrYx.TVShopping.Modules.ProductExport.ProductExporter.FetchProductData(ExportSkns sourceSkns) in C:\\OrYxDev\\CSharp 2.0\\TVShopping\\TVShoppingCommonExtended\\Modules\\ProductExport\\ProductExporter.cs:line 132"

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 29-Oct-2011 10:17:34   

Use EntityField2 instead of EntityField, coz you are using Adapter:

EntityField2 fieldSkuLength = new EntityField2("SkuLength", new DbFunctionCall("LEN({0})", new object[] { ProductFields.Sku }));
David Elizondo | LLBLGen Support Team
Jamanga
User
Posts: 93
Joined: 21-Jul-2006
# Posted on: 30-Oct-2011 23:26:02   

Hi daelmo - that was it, thank you!