I'm setting up a store that sells watches. The store will have filtering and I need some advice on the best way to do this.
I need a way to check if the filter has been applied and if so to filter the products, if not then not filter.
I have tried creating a dynamic query but this doesn't work. What is the best way of doing this?
(More Context)
If the user has filtered the watches to only show watches that are for men that's fine, I can query that using below:
var query = Model.Children().Where(x => x.GetPropertyValue<string>("filterGender").ToLower().Replace(" ","-") == Request.QueryString["gender"]);
The hard part comes when having multiple filtering. So if the user was to filter by gender and case material then i could create the query for that, it is just knowing when they are querying or now.
I basically need a way to dynamically build the query.
You should really be using Examine especially if you have a lot of products.
As long as your linq is an IQueryable you can keep it going.
Dim events = From [event] In db.TrackingEvents
Where [event].DateCreated >= params.startDate And [event].DateCreated <= params.endDate
Order By [event].DateCreated Descending
Select New SearchResultObj With {
}
If Not String.IsNullOrEmpty(params.email) Then
events = events.Where(Function(x) x.Email = params.email)
End If
If Not String.IsNullOrEmpty(params.ip) Then
events = events.Where(Function(x) x.IP = params.ip)
End If
If Not String.IsNullOrEmpty(params.acctNo) Then
events = events.Where(Function(x) x.AcctNo = params.acctNo)
End If
Finally got around to giving this ago. Firstly selecting all of the pages then sorting them into what I need doesn't seem the best way possible as there could end up being 1000+ pages (or products when I'm done with them) so this could ruin page speed. Secondly, what if more than more than one filter was added?
Dynamic Query of Products
Hi.
I'm setting up a store that sells watches. The store will have filtering and I need some advice on the best way to do this.
I need a way to check if the filter has been applied and if so to filter the products, if not then not filter.
I have tried creating a dynamic query but this doesn't work. What is the best way of doing this?
(More Context)
If the user has filtered the watches to only show watches that are for men that's fine, I can query that using below:
The hard part comes when having multiple filtering. So if the user was to filter by gender and case material then i could create the query for that, it is just knowing when they are querying or now.
I basically need a way to dynamically build the query.
Thanks, Lewis
You should really be using Examine especially if you have a lot of products.
As long as your linq is an IQueryable you can keep it going.
Thanks! I will take a look at this over the next few days.
Hi Brad,
Finally got around to giving this ago. Firstly selecting all of the pages then sorting them into what I need doesn't seem the best way possible as there could end up being 1000+ pages (or products when I'm done with them) so this could ruin page speed. Secondly, what if more than more than one filter was added?
thanks, Lewis
is working on a reply...