2

I'm stuck with the following scenario, i have 2 tables called (Products and Categories). the field CategoryID in Products table has a FK to the Categories table.

Now for my data table in my CMS I'm looking for a way to sort the products based on the Category Title. This Title is available when I'm looking at a DAL.Product item but ofcourse not when I'm querying the products table.

Is this possible using native Subsonic or do I need to create a detour? I could just sort them on the CategoryID but that is not so straightforward for the end-users cause all other columns can be sorted alphabeticly.

Kind regards ans thanks for your time, Mark

ps: I'm getting paged results so sorting the collection after it's filled is not an option for me...

marapet
  • 54,856
  • 12
  • 170
  • 184
Mark
  • 49
  • 3

1 Answers1

0

You may try something along those lines.

List<DAL.Product> lst = DAL.DB.Select().From<DAL.Product>()
    .InnerJoin<DAL.Category>
    .OrderAsc(DAL.Category.CategoryTitleColumn.ColumnName)
    .Paged(x,y)
    .ExecuteTypedList<DAL.Product>();
marapet
  • 54,856
  • 12
  • 170
  • 184
  • Thank you that worked perfectly! By the way, what's the main difference between a List and Subsonic.Collection, do you prefer one of the two and if so why? Thanks m8! – Mark Mar 25 '11 at 20:55
  • The Collections are created by SubSonic, they are strongly typed, and you may change the template used to create them yourself if you need to add some functions of your own, whereas List is generic and defined in the official .NET Framework. I tend to use List and work with it like any other list of objects. – marapet Mar 25 '11 at 21:18
  • Ok great explanation, I think I'm switching to List too, so it will be easier if we need to switch form Subsonic one day. I don't want to be rude but I have one other problem where I cant find an answer for here or in the forums [link[(http://stackoverflow.com/questions/5386825/c-subsonic-2-2-many-to-many-relationship-and-pagination-problem). Thank you again! – Mark Mar 26 '11 at 13:03