views:

20

answers:

1

Hi,

I have a few tables, Listings, ListingImages and a few others related to Listings. ListingImages is related to Listings so that you can have many ListingImages per Listing.

When I query this table I do;

IQueryable<Listing> ListingToSendToView = (from x in DBEntities.ListingSet.Include("ListingImages")
                                                                          .Include("OtherTables")
                                           where x.Listing.ID == (int)LID
                                           orderby x.ID descending
                                           select x).First();

Now this is fine. However, I now want to sort the ListingImages independently within each Listing (by an ImageOrder column I have in that table).

How can I do this and pass all my Includes(...). Would it be bad form to sort the ListingImages within the View as this solution seems to work?

Cheers

+1  A: 

Hey,

I think you are going to have to sort it in the view, because if you want each group to have a different sorting, you have to do that manually. The only other option is to copy it to a dictionary or list structure and sort and copy it in the order, then return that from the controller... though I don't even know where to begin on that one.

I don't think sorting on the view is bad form, because it's part of the UI logic (or the UI's needs anyway)... it would be bad form to query data within the view, and be careful not to put too much logic in (I don't know the complexity you are talking about), but as long as its only sorting, I think that's OK.

HTH.

Brian
Thanks for your answer Brian. It's a simple sort so I will just do it in the view.
sheefy