GroupByCollection with TypedList

Posts   
 
    
rai
User
Posts: 41
Joined: 25-Jan-2007
# Posted on: 08-May-2008 05:31:16   

I am using llblgen version 2.5 with adapter. Visual studio with C# and sql server 2004.

I had created a typedlist and now i want to group the typedlist but i dnt know how to do it.

this is what i was trying so far..cudnt get it so thot to drop a post for assistance.

static public ITypedListLgp2 Transfer() { DataAccessAdapter adapter = new DataAccessAdapter(dbConnectionString()); TransferDataTypedList data = new TransferDataTypedList(); IEntityField2 fields = data.GetFieldsInfo(); IGroupByCollection groupByClause = new GroupByCollection(); groupByClause.Add(TransactionsSummaryFields.CustomerCode); ISortExpression sort = new SortExpression(); sort.Add(CustomerMasterFields.AreaCode | SortOperator.Ascending); sort.Add(CustomerMasterFields.SalesCode | SortOperator.Ascending); //adapter.FetchTypedList(fields, data, data.GetFieldsInfo(), 0, null,true, groupByClause); return data; }

iam getting the error ...please help me out

rai
User
Posts: 41
Joined: 25-Jan-2007
# Posted on: 08-May-2008 06:39:48   

I tried to bit modify the function but still getting no luck........this is wat i did, i dont know am i doing the right thing or not.

static public DataTable Transfer(string pub,int month,int year) { DataAccessAdapter adapter = new DataAccessAdapter(dbConnectionString()); TransferDataTypedList data = new TransferDataTypedList(); ResultsetFields fields = new ResultsetFields(2); fields.DefineField(TransactionsSummaryFields.CustomerCode, 0, "customer"); IGroupByCollection groupByClause = new GroupByCollection(); groupByClause.Add(fields[0]); IRelationPredicateBucket bucket = new RelationPredicateBucket(TransactionsSummaryFields.PubCode == pub & TransactionsSummaryFields.Period == month & TransactionsSummaryFields.Year == year); ISortExpression sort = new SortExpression(); sort.Add(CustomerMasterFields.AreaCode | SortOperator.Ascending); sort.Add(CustomerMasterFields.SalesCode | SortOperator.Ascending); DataTable tlist = new DataTable(); adapter.FetchTypedList(fields,tlist,bucket, 0, null, true, groupByClause); return tlist; }

iam getting the following error

[NullReferenceException: Object reference not set to an instance of an object.] SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.PreprocessQueryElements(IEntityFields2 fieldCollectionToFetch, IRelationPredicateBucket filterBucket) +529 SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.CreateQueryFromElements(IEntityFields2 fieldCollectionToFetch, IRelationPredicateBucket filterBucket, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, Boolean allowDuplicates, IGroupByCollection groupByClause, Int32 pageNumber, Int32 pageSize, IFieldPersistenceInfo[]& persistenceInfo, IRetrievalQuery& selectQuery) +129 SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchTypedList(IEntityFields2 fieldCollectionToFetch, DataTable dataTableToFill, IRelationPredicateBucket filterBucket, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, Boolean allowDuplicates, IGroupByCollection groupByClause, Int32 pageNumber, Int32 pageSize) +166 SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchTypedList(IEntityFields2 fieldCollectionToFetch, DataTable dataTableToFill, IRelationPredicateBucket filterBucket, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, Boolean allowDuplicates, IGroupByCollection groupByClause) +34 WebCircuBL.TransactionsSummary.Transfer(String pub, Int32 month, Int32 year) in C:\Documents and Settings\jchand\My Documents\WebCirculation\WebCircuBL\TransactionsSummary.cs:152 Circulation.DataTransfer.Page_Load(Object sender, EventArgs e) in C:\Documents and Settings\jchand\My Documents\WebCirculation\Circulation\Circulation\DataTransfer.aspx.cs:30 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +33 System.Web.UI.Control.OnLoad(EventArgs e) +99 System.Web.UI.Control.LoadRecursive() +47 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1436

please help me

Walaa avatar
Walaa
Support Team
Posts: 14994
Joined: 21-Aug-2005
# Posted on: 08-May-2008 08:57:14   
     ResultsetFields fields = new ResultsetFields(2);
     fields.DefineField(TransactionsSummaryFields.CustomerCode, 0, "customer");
     IGroupByCollection groupByClause = new GroupByCollection();
     groupByClause.Add(fields[0]);

Your second piece of code won't work. Because you are grouping on a field with an alias that's not used in the TypedList.

The following code should work.

DataAccessAdapter adapter = new DataAccessAdapter();
TransferDataTypedList data  = new TransferDataTypedList();
IGroupByCollection groupByClause = new GroupByCollection();

IEntityFields2 fields = data .GetFieldsInfo();  
groupByClause.Add(fields[x]);

adapter.FetchTypedList(fields, data, data .GetRelationInfo(), 0, null, true, groupByClause);

Where x is the index of the field in the TypedList in which you'd group on. Also you have to make sure that other fields in the TypedList have Aggregate functions asspciated with them. You can apply aggregate functions in the TypedList editor, and also in your code.

Try the above code first and if it succeeds then try to add the sort code as follows:

         ISortExpression sort = new SortExpression();
         sort.Add(fields[y] | SortOperator.Ascending);
         sort.Add(fields[z] | SortOperator.Ascending);
rai
User
Posts: 41
Joined: 25-Jan-2007
# Posted on: 08-May-2008 09:50:56   

Walaa,

now how can i add the filter... i want to do something like thing

IRelationPredicateBucket bucket = new RelationPredicateBucket(TransactionsSummaryFields.PubCode == pub & TransactionsSummaryFields.Period == month & TransactionsSummaryFields.Year == year);

is it possible????

Walaa avatar
Walaa
Support Team
Posts: 14994
Joined: 21-Aug-2005
# Posted on: 08-May-2008 10:21:11   

Same thing use the fields[] list as follows.

IRelationPredicateBucket bucket = new RelationPredicateBucket(fields[a] == pub &
         fields[b] == month & fields[c] == year);
rai
User
Posts: 41
Joined: 25-Jan-2007
# Posted on: 08-May-2008 10:36:02   

IRelationPredicateBucket bucket = new RelationPredicateBucket(fields[1] == pub & fields[2] == month & fields[3] == year);

Error 4 Operator '==' cannot be applied to operands of type 'SD.LLBLGen.Pro.ORMSupportClasses.IEntityField2' and 'string' 153 74 WebCircuBL Error 5 Operator '==' cannot be applied to operands of type 'SD.LLBLGen.Pro.ORMSupportClasses.IEntityField2' and 'int' 153 93 WebCircuBL Error 6 Operator '==' cannot be applied to operands of type 'SD.LLBLGen.Pro.ORMSupportClasses.IEntityField2' and 'int' 153 114 WebCircuBL

...................... and where will i include bucket over here adapter.FetchTypedList(fields, data, data.GetRelationInfo(), 0, sort, true, groupByClause);


sort.Add(fields[6] | SortOperator.Ascending); sort.Add(fields[7] | SortOperator.Ascending);

Error 7 Operator '|' cannot be applied to operands of type 'SD.LLBLGen.Pro.ORMSupportClasses.IEntityField2' and 'SD.LLBLGen.Pro.ORMSupportClasses.SortOperator' 155 21 WebCircuBL Error 8 Operator '|' cannot be applied to operands of type 'SD.LLBLGen.Pro.ORMSupportClasses.IEntityField2' and 'SD.LLBLGen.Pro.ORMSupportClasses.SortOperator' 156 21 WebCircuBL

Walaa avatar
Walaa
Support Team
Posts: 14994
Joined: 21-Aug-2005
# Posted on: 08-May-2008 14:38:29   

Instead of:

IEntityFields2 fields = data .GetFieldsInfo();

Try:

EntityFields2 fields = data .GetFieldsInfo();

rai
User
Posts: 41
Joined: 25-Jan-2007
# Posted on: 08-May-2008 23:26:55   

Getting no luck in this so swtiching to stored procedure