Derived table defination getting error

Posts   
 
    
Posts: 87
Joined: 17-May-2011
# Posted on: 11-May-2012 12:14:03   

Hi there

Can you please tell what's wrong with the code snippet given below I am getting this error "Object reference not set to an instance of an object."

 OrderCollection oOrderCollection = new OrderCollection();
            ResultsetFields oResultsetFields = new ResultsetFields(2);
            RelationCollection oRelationCollection = new RelationCollection();
            IPredicateExpression oPredicateExpression = new PredicateExpression();
            PredicateExpression oPredicateExpressionParent = new PredicateExpression();
            IPrefetchPath oPrefetchPath = new PrefetchPath(EntityType.OrderEntity);
            ISortExpression oSortExpression = new SortExpression();

            EntityField installmentAmount = new EntityField("InstallmentAmount", OrderFields.Amount * 1, AggregateFunction.Sum, typeof(decimal));
            oResultsetFields.DefineField(OrderFields.ParentOrder, 0);
            oResultsetFields.DefineField(installmentAmount, 1);

            oPredicateExpression.Add(OrderFields.ParentOrder != DBNull.Value);
            oPredicateExpression.AddWithAnd(OrderFields.ClientId == clientId);
            oPredicateExpression.AddWithAnd(OrderFields.OrderStatus != OrdersEnum.OrderStatus.Cancelled);

            GroupByCollection oGroupByCollection = new GroupByCollection(oResultsetFields[0]);
            DerivedTableDefinition oDerivedTableDefinition = new DerivedTableDefinition(oResultsetFields, "Installments", oPredicateExpression, oGroupByCollection);
            IDynamicRelation oDynamicRelation = new DynamicRelation(oDerivedTableDefinition, JoinHint.Inner, EntityType.OrderEntity, "O", ((new EntityField(OrderFieldIndex.ParentOrder.ToString(), "Installments", typeof(int)) == OrderFields.Id.SetObjectAlias("O"))));
            oRelationCollection.Add(oDynamicRelation);
            oRelationCollection.SelectListAlias = "O";

            oPredicateExpressionParent.Add(new EntityField2("InstallmentAmount", "Installments", typeof(decimal)) != OrderFields.Amount.SetObjectAlias("O"));
            oPredicateExpressionParent.AddWithAnd(OrderFields.ClientId.SetObjectAlias("O") == clientId);
            oPrefetchPath.Add(OrderEntity.PrefetchPathOrders, 0, oPredicateExpression);

            oOrderCollection.GetMulti(oPredicateExpressionParent, oRelationCollection);

and the stack trace of the error is as follows:

at SD.LLBLGen.Pro.ORMSupportClasses.DbSpecificCreatorBase.CreateParameter(IEntityFieldCore field, IFieldPersistenceInfo persistenceInfo, ParameterDirection direction, Object valueToSet) at SD.LLBLGen.Pro.ORMSupportClasses.FieldCompareValuePredicate.ToQueryText(Boolean inHavingClause) at SD.LLBLGen.Pro.ORMSupportClasses.PredicateExpression.ToQueryText(Boolean inHavingClause) at SD.LLBLGen.Pro.ORMSupportClasses.PredicateExpression.ToQueryText(Boolean inHavingClause) at SD.LLBLGen.Pro.ORMSupportClasses.DynamicQueryEngineBase.AppendWhereClause(IPredicate filter, QueryFragments destination, IQuery query) at SD.LLBLGen.Pro.DQE.SqlServer.DynamicQueryEngine.CreateSelectDQ(IEntityFieldCore[] selectList, IFieldPersistenceInfo[] fieldsPersistenceInfo, IRetrievalQuery query, 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, DbConnection connectionToUse, IPredicate selectFilter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relationsToWalk, Boolean allowDuplicates, IGroupByCollection groupByClause) at SD.LLBLGen.Pro.DQE.SqlServer.DynamicQueryEngine.CreatePagingSelectDQ(IEntityFieldCore[] selectList, IFieldPersistenceInfo[] fieldsPersistenceInfo, DbConnection connectionToUse, IPredicate selectFilter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relationsToWalk, Boolean allowDuplicates, IGroupByCollection groupByClause, Int32 pageNumber, Int32 pageSize) at SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.PerformGetMultiAction(ITransaction containingTransaction, IEntityCollection collectionToFill, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IPredicate selectFilter, IRelationCollection relations, IPrefetchPath prefetchPathToUse, ExcludeIncludeFieldsList excludedIncludedFields, Int32 pageNumber, Int32 pageSize) at SD.LLBLGen.Pro.ORMSupportClasses.EntityCollectionBase1.GetMulti(IPredicate selectFilter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relations, IPrefetchPath prefetchPathToUse, ExcludeIncludeFieldsList excludedIncludedFields, Int32 pageNumber, Int32 pageSize) at SD.LLBLGen.Pro.ORMSupportClasses.EntityCollectionBase1.GetMulti(IPredicate selectFilter, IRelationCollection relations)

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 11-May-2012 12:16:35   

Runtime library version (build number), please.

Posts: 87
Joined: 17-May-2011
# Posted on: 11-May-2012 12:25:54   

SD.LLBLGen.Pro.DQE.SqlServer.NET20.dll - 3.1.11.0221 SD.LLBLGen.Pro.LinqSupportClasses.NET35.dll - 3.1.11.0426 SD.LLBLGen.Pro.ORMSupportClasses.NET20.dll - 3.1.11.0427

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 11-May-2012 14:13:25   

oPredicateExpressionParent.Add(new EntityField2...

EntityField2 is used in the Adapter template set, not in SelfServicing, please use EntityField instead.

Posts: 87
Joined: 17-May-2011
# Posted on: 11-May-2012 14:43:15   

Thanks buddy it worked for me simple_smile , but let inform you in the examples in the Documentation the second example is wrong for self service, I myself added entityfield2 by seeieng the example from there the link is here : http://www.llblgen.com/documentation/2.6/Using%20the%20generated%20code/gencode_derivedtabledynamicrelation.htm

Please correct that one.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 11-May-2012 19:11:21   

chirag.vashisht wrote:

Thanks buddy it worked for me simple_smile , but let inform you in the examples in the Documentation the second example is wrong for self service, I myself added entityfield2 by seeieng the example from there the link is here : http://www.llblgen.com/documentation/2.6/Using%20the%20generated%20code/gencode_derivedtabledynamicrelation.htm

Please correct that one.

You are right, there is a typo in the line:

IPredicate filter = (new EntityField2("Total", "OrderDetailTotals", typeof(int)) > 5000);

it should be

IPredicate filter = (new EntityField("Total", "OrderDetailTotals", typeof(int)) > 5000);

We will look into it.

David Elizondo | LLBLGen Support Team
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 14-May-2012 11:12:22   

Fixed.

Frans Bouma | Lead developer LLBLGen Pro