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 ?
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.
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 :)
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 ?
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.
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 :)
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 :)
is working on a reply...