Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6243957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:14:16+00:00 2026-05-24T12:14:16+00:00

Trying to build a linq query based on parameters a user selects (reporting) but

  • 0

Trying to build a linq query based on parameters a user selects (reporting) but it’s not working out properly… the entire table is loaded instead of the filtered result set requested. Here is the code that I am using:

Public Sub GetResults()
    Using ctx As New ReportingEntities()

        Dim results As IQueryable(Of Orders) = ctx.Orders

        ' get reason params
        If lbReason.GetSelectedIndices().Count() > 0 Then
            Dim reasons = (From i As ListItem In lbReason.Items
                           Where i.Selected
                           Select Integer.Parse(i.Value)).ToList()

            If reasons IsNot Nothing Then
                Dim where =
                        CommonDataUtils.BuildOrExpressionTree(Of Orders, Integer)(reasons,
                                                                                                Function(r) r.ID)
                results.Where(where)
            End If
        End If

        ' get commodity params
        If lbCommodity.GetSelectedIndices().Count() > 0 Then
            Dim comms = (From i As ListItem In lbCommodity.Items
                           Where i.Selected
                           Select i.Value).ToList()

            If comms IsNot Nothing Then
                Dim where =
                    CommonDataUtils.BuildOrExpressionTree(Of Orders, String)( _
                        DirectCast(comms, IEnumerable(Of String)),
                        Function(r) r.Affected_Commodity)
                results.Where(where)
            End If
        End If

        ' get disposition params
        If lbDisposition.GetSelectedIndices().Count() > 0 Then
            Dim disps = (From i As ListItem In lbDisposition.Items
                       Where i.Selected
                       Select Integer.Parse(i.Value)).ToList()

            If disps IsNot Nothing Then
                Dim where =
                    CommonDataUtils.BuildOrExpressionTree(Of Orders, Integer)( _
                                                    disps,
                                                    Function(r) r.ID)
                results.Where(where)
                filter.Add(where)
            End If
        End If


        ' get facility params
        If lbProdFacility.GetSelectedIndices().Count() > 0 Then
            Dim facs = (From i As ListItem In lbProdFacility.Items
                       Where i.Selected
                       Select Integer.Parse(i.Value)).ToList()

            If facs IsNot Nothing Then
                Dim where =
                        CommonDataUtils.BuildOrExpressionTree(Of Orders, Integer)(facs,
                                                                            Function(r) r.ID)
                results.Where(where)
                filter.Add(where)
            End If
        End If

        ' get customer number params
        Dim custnums As List(Of Integer) = If(ViewState("cust_nums") Is Nothing, Nothing, ViewState("cust_nums"))
        If custnums IsNot Nothing AndAlso custnums.Count > 0 Then
            Dim where = CommonDataUtils.BuildOrExpressionTree(Of Orders, Integer) _
                        (custnums, Function(i) i.ID)
            results.Where(where)
            filter.Add(where)
        End If

        ' get reason code params
        Dim resnums As List(Of Integer) = If(ViewState("res_nums") Is Nothing, Nothing, ViewState("res_nums"))
        If resnums IsNot Nothing AndAlso resnums.Count > 0 Then
            Dim where = CommonDataUtils.BuildOrExpressionTree(Of Orders, Integer) _
                        (resnums, Function(i) i.ID)
            results.Where(where)
            filter.Add(where)
        End If

        ' get date params
        If IsDate(startDate.Value.Trim()) And IsDate(endDate.Value.Trim()) Then
            Dim sdate As DateTime
            Dim edate As DateTime
            DateTime.TryParse(startDate.Value.Trim(), sdate)
            DateTime.TryParse(endDate.Value.Trim(), edate)


            If edate > sdate Then
                Dim dateWhere As Expression(Of Func(Of Orders, Boolean)) =
                    Function(d) (d.Date_Rejected >= sdate And d.Date_Rejected <= edate)
                results.Where(dateWhere)
                filter.Add(dateWhere)
            End If



        ' populate results grid
        grd.DataSource = results
        grd.DataBind()

    End Using
End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T12:14:17+00:00Added an answer on May 24, 2026 at 12:14 pm

    LINQ Queries are immutable, like strings. Remember how this:

    s + " world"
    

    … does not actually change the value of s? It works the same way with LINQ queries.

    results.Where(where)
    

    … does not change the query. You might be looking for:

    results = results.Where(where)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to find the best way to build a dynamic linq query
I'm trying to write a dynamic Linq 2 Sql query using Expressions trees but
I'm trying to dynamically build a LINQ query for LINQ to Entities so that
I am trying to build out a useful 3d game engine out of the
I am trying to build a dependency graph of tables based on the foreign
I'm trying to build a SelectList from an Enum . Why are the Linq
i am trying to build linq expression to solve my problem. I have list
Trying to build a GUI application in Java/Swing. I'm mainly used to painting GUIs
I trying to build and compile my xcodeproj in command line and it is
I'm trying to build a grammar with the following: NUMERIC: INTEGER | FLOAT |

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.