Forum:  LLBLGen Pro Runtime Framework

Thread:  Sorting by 2 fields


Stoop (User)   Posted on: 24-Apr-2004 12:18:29.
Hi

Well, I've been working with LLGen for a month now & for the first time I need to sort a typedList by 2 fields. I looked in the help, both in the section on TypedLists & also the "How do I.." No examples (Maybe a good new "How do I.." question")

I tried playing with the code, but so far no luck... So - I need some help.

I simple want to sort a typedList by field A, then by field B, both in ASC order....

TIA
Steve
Otis (LLBLGen Pro Team)   Posted on: 24-Apr-2004 12:54:00.
Just add 2 sort clauses to the sortexpression, instead of one. In the right order of course (the first one is also the main sort clause, the second sorts inside the first one)

Stoop (User)   Posted on: 24-Apr-2004 13:42:31.
Would it be too much to ask for a bit of sample code?

Thx

Steve
Otis (LLBLGen Pro Team)   Posted on: 24-Apr-2004 14:22:52.
Stoop wrote:
Would it be too much to ask for a bit of sample code?

Sorry, I assumed it was selfexplaining, here we go Regular Smiley ->

(VB.NET, you use VB.NET iirc)

Dim sorter As ISortExpression = New SortExpression()
sorter.Add(SortClauseFactory.Create(CustomerFieldIndex.CompanyName, SortOperator.Ascending))
sorter.Add(SortClauseFactory.Create(CustomerFieldIndex.ContactName, SortOperator.Ascending))

and now pass the sorter object to a GetMulti() call for example. It will then sort ascending first on CompanyName, then on ContactName.

For typed lists, please take note that you have to refer to the fields in the typed list which can be in different entities, so you have to specify different field indexes, like you also do with filters.


Stoop (User)   Posted on: 25-Apr-2004 09:43:54.
Otis wrote:
Stoop wrote:
Would it be too much to ask for a bit of sample code?

Sorry, I assumed it was selfexplaining, here we go Regular Smiley ->

(VB.NET, you use VB.NET iirc)

Dim sorter As ISortExpression = New SortExpression()
sorter.Add(SortClauseFactory.Create(CustomerFieldIndex.CompanyName, SortOperator.Ascending))
sorter.Add(SortClauseFactory.Create(CustomerFieldIndex.ContactName, SortOperator.Ascending))

and now pass the sorter object to a GetMulti() call for example. It will then sort ascending first on CompanyName, then on ContactName.

For typed lists, please take note that you have to refer to the fields in the typed list which can be in different entities, so you have to specify different field indexes, like you also do with filters.


Thats it??? Geez. I thought it was something different. I was trying something along the lines of:

Dim SortExpression As ISortExpression = New SortExpression(SortClauseFactory.Create(CustomerFieldIndex.CompanyName, SortOperator.Ascending))

Dim SortExpression2 As ISortExpression = New SortExpression(SortClauseFactory.Create(CustomerFieldIndex.ContactName, SortOperator.Ascending))

Dim Iclause As ISortClause = New SortClause(PropertyLocationImageObject.ImageOrder, SortOperator.Ascending)

SortExpression.Add(SortExpression2) ...

Which obviously didn't work, but I was thinking that's how one did it based on filtering..

Which brings me to a point: IMHP the help needs to be WAY clearer on things. For example, the VB example in the HELP for sorting (adapter method) is:

Dim sorterInvoices As ISortExpression = New SortExpression( _
    SortClauseFactory.Create(InvoicesFieldIndex.ExtendedPrice, SortOperator.Descending))
adapter.FetchTypedView(invoices.GetFieldsInfo(), invoices, bucket, 0, sorter, True)*

* Notice the typo? 'sorter' should be: 'sorterInvoices'!!

Why not make it:

Dim sorterInvoices As ISortExpression = New SortExpression()
Dim Iclause1 As ISortClause = SortClauseFactory.Create(SortClauseFactory.Create(CustomerFieldIndex.CompanyName, SortOperator.Ascending)
sorterInvoices.Add(Iclause1)
adapter.FetchTypedView(invoices.GetFieldsInfo(), invoices, bucket, 0, sorterInvoices, True)

A couple of more lines, but does same thing, and sure is easier to read & digest, especially for new users.

I have virtually no complaints about LLGen - it's a fantastic tool and you, Fran, have always ansered question & provided EXCELLENT support. My one & only complaint is about the HELP. I really think it needs to be redone, or a "QuickStart" section added aimed at new users to get them up and running as quick as possible. I hate posting questions here in forum that probably a lot of people probably consider "Dumb", but I do simply for the fact that I can't figure out to do what I need to do from the help & I simply don't have much time to sit down and work with my project code until I come up with the solution.

Had, what you mentioned above as "obvious", this somewhere in the help, I wouldn't had to post it here. How to sort by 2 fields probably is a common thing to do and at the very least belongs in the "How do I.." section....

Sure, the HELP is beautifully written in terms of being technical. But don't forget about the new guy, Fran. What is obvious to you is not necessarily obvious to everyone else...

Just my opinion & nothing more ..

Thanks for your help!

Steve





Otis (LLBLGen Pro Team)   Posted on: 25-Apr-2004 11:45:22.
Good suggestion, Steve Regular Smiley It's always hard to find the line where you have to start explaining things and where you can assume things are obvious. Your suggestion is noted and will be included in the next revision of the docs. (with the gui updates).

Stoop (User)   Posted on: 25-Apr-2004 13:01:43.
Hi

Well, Frans - why not ask the public? Create a thread for suggestions on improving the help, where are typos are, et... I'm sure I can't be the only one that has suggestions on how to improve the HELP...

Also - probably some of the posts (like mine) are good canditates for the "How do I.." section. Maybe if you could keep track of some of the basic questions and simply add them to the HELP....

Just a suggestion..

Steve