Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


These support forums are now closed for new topics and comments.
Please head on over to http://eureka.ucommerce.net/ for support.

  • Klaus Pedersen 15 posts 71 karma points
    Mar 11, 2013 @ 21:12
    Klaus Pedersen
    0

    Sort Products

    I've been trying to figure out how to sort products by price before listing them in the catalog. Anyone else that has experienced difficulties with that? And perhaps has a solution for it ?

  • Morten Skjoldager 440 posts 1499 karma points
    Mar 11, 2013 @ 21:21
    Morten Skjoldager
    100

    wont this do the trick? 

     

                var products = Product.All().ToList();

                var priceGroup = your desired pricegroup

                products.OrderBy(x => x.GetPrice(priceGroup).Price);

     

    Maybe you need the list of products to be inistialized First. (so the linq API won't hit the database with the query instead of the List). This may some times cause problems as Linq to List is more intelligent than Linq to SQL because Linq to SQL does not know about the data structure. IF that makes any sense.  

     

  • Klaus Pedersen 15 posts 71 karma points
    Mar 11, 2013 @ 23:31
    Klaus Pedersen
    0

    Thanks u saved the day i tried the thing u described but wouldent work with linq to sql but wit the list it works like a charm :)

  • Morten Skjoldager 440 posts 1499 karma points
    Mar 12, 2013 @ 07:56
    Morten Skjoldager
    0

    Allrighty :) Glad to help. Remember to think about how you load products from the DB. Most of the time you will get "saved" by cache. But google "n+1 problem" if you haven't thought about performance :) 

Please Sign in or register to post replies

Write your reply to:

Draft