Copied to clipboard

Flag this post as spam?

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


  • Lewis Smith 211 posts 620 karma points c-trib
    Oct 11, 2017 @ 08:44
    Lewis Smith
    0

    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:

    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.

    Thanks, Lewis

  • Brad 69 posts 97 karma points
    Oct 13, 2017 @ 19:18
    Brad
    1

    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
    
  • Lewis Smith 211 posts 620 karma points c-trib
    Oct 18, 2017 @ 15:25
    Lewis Smith
    0

    Thanks! I will take a look at this over the next few days.

  • Lewis Smith 211 posts 620 karma points c-trib
    Oct 31, 2017 @ 15:01
    Lewis Smith
    0

    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

Please Sign in or register to post replies

Write your reply to:

Draft