Help me sort sorting ;)

Posts   
 
    
Posts: 497
Joined: 08-Apr-2004
# Posted on: 27-Aug-2004 11:47:14   

Hi,

In my old postings here, we discussed various architectures and how we were working with the gen'd data later and what kind of BL we had. I decided on a level of abstraction (Wayne hada similar model), whereby we made it a rule that the PL does not know about LLBL, instead it calls methods on the BL to get the entities or ICollections that are needed. So the BL could pass back a datatable, custom collection, or single entity classes.

Right - my question is, using this type of design, I need my BL methods to accept "sort" parameters from the PL to determine what to sort by. THis is causing me some grief. In our old app, we would just pass through a string like "Title asc" and the BL would apply that to the resulting recordset. Now though, I need to construct a sort expression in LLBL, and the only solution I can think of is to allow the PL to pass to the BL a pre-defined LLBL sort expression - but this breaks all my architecture rules rage It strikes me as a vaild PL action to want to sort the data, but how can it do this without being involved in the actual BL/DL code........hmmmmmmmm

What should I do? What have other people done? Gotta sort this out (how many sort-related puns can I make in this post!!)

Thanks

netclectic avatar
netclectic
User
Posts: 255
Joined: 28-Jan-2004
# Posted on: 27-Aug-2004 12:10:55   

Why can't it work the same as previously? The PL passes a list of fields to sort by and the BL has a function to construct a sort expression given this list as a parameter?

After a quick play, maybe something like this would do the trick??

        public static ISortExpression BuildSortExpression(EntityCollection ents, Hashtable sortFields)
        {
            ISortExpression sorter = new SortExpression();
            IEntityFields2 fields = ents.EntityFactoryToUse.CreateFields();
    
            foreach (DictionaryEntry de in sortFields)
            {
                IEntityField2 field = fields[(string)de.Key];
                if (((string)de.Value).ToUpper().Equals("ASC"))
                    sorter.Add(new SortClause(field, null, SortOperator.Ascending));
                else
                    sorter.Add(new SortClause(field, null, SortOperator.Descending));
            }
            return sorter;
        }
wayne avatar
wayne
User
Posts: 611
Joined: 07-Apr-2004
# Posted on: 27-Aug-2004 13:25:41   

I am doing sorting, no problem. simple_smile

My PL passes the field i want to sort on into my BL.

My BL takes the string and finds the matching DL Enum Field.

Then the BL constructs a SortExpression -> Calls the method -> DL Fetches the Data and passes it back to BL, PL.

I do my filtering in a simular manner - where the filter criteria gets selected / entered by the user via the PL.

I hope this helps you sort the problem outstuck_out_tongue_winking_eye

Posts: 497
Joined: 08-Apr-2004
# Posted on: 31-Aug-2004 00:00:05   

Ah thanks guys.

I was posting this for a colleage, and the thinking i did on this was along the lines of "hmm, might be tricky to get from 'customer_name asc' to an LLBLGen sort expression".... but, you've both corrected me there, I'm afraid its my relative inexperiebce of .NET showing through again - i'm still in the "wow - .net can do this" stage!

Just out of curiosity, do either of you guys allow the PL to sort the data once it has it, or do you force the sorting to be done through the BL?

Matt

erichar11
User
Posts: 268
Joined: 08-Dec-2003
# Posted on: 31-Aug-2004 04:26:57   

pmfji, but how are you guys generating the entities and collections which are returned to the pl? I noticed that there was a template generator which seems to be for generating entities for this purpose. Not sure though. I also don't want my pl to know about the llblgen entities but I also don't want to spend a lot of time creating derived entities and collections and so forth. Any help would be appreciated, as always.

wayne avatar
wayne
User
Posts: 611
Joined: 07-Apr-2004
# Posted on: 31-Aug-2004 09:30:22   

I think MattWoberts has his own template that he created.

Have a look at the following threads: 1. Passing Entities accross tiers - http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=802 2. Collections in the business layer - http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=811 3. Passing Collections or DataTables - http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=834

I think that you will get all your ansers from these threads.

Posts: 497
Joined: 08-Apr-2004
# Posted on: 31-Aug-2004 11:07:47   

I do indeed - we had the same concerns about the PL using LLBL - I wont go into details because waynehas kindly provided all the links.

In summary: My PL works with gen'd entities that my template creates, but the entities are very simple and generic to any application, thus the PL is not bound to LLBL.

Shout if you want me to post the template

Jackk100
User
Posts: 48
Joined: 11-Jan-2005
# Posted on: 15-Jan-2005 00:33:25   

Don't want to soak up reading time, but just found the post in this thread by netclectic and it was exactly what I was looking for (trying to do) and I wanna say Thanks.

BTW, it worked as is.

After a quick play, maybe something like this would do the trick??

        
public static ISortExpression BuildSortExpression(EntityCollection ents, Hashtable sortFields)
etc....

  • Jack