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

  • SEARCH
  • Home
  • 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 6362075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:51:39+00:00 2026-05-24T23:51:39+00:00

I use a dynamic filter, that filters a collection using object properties, operators and

  • 0

I use a dynamic filter, that filters a collection using object properties, operators and values. Now, if the property is a string, the operator is “contains” and the value is “word”, the filtered objects containing the “world” should be filtered accordingly.

In Linq I have the Expression.Equal, NotEqual, GreaterThanOrEqual, LessThanOrEqual

but don’t have “Contains“. How to replace it?

Consider the following code (in VB.NET, but does not matter)

  Select Case compOp
    Case ComparisonOperator.Contains
      ' ?????? WHAT HERE ???? '
      filterExpression = Expression.Lambda(Of Func(Of PropertyType, Boolean))(Expression.Equal(myObjPropertyParam, myConstExpression), myObjParam)

    Case ComparisonOperator.Different
      filterExpression = Expression.Lambda(Of Func(Of PropertyType, Boolean))(Expression.NotEqual(myObjPropertyParam, myConstExpression), myObjParam)

    Case ComparisonOperator.Equal
      filterExpression = Expression.Lambda(Of Func(Of PropertyType, Boolean))(Expression.Equal(myObjPropertyParam, myConstExpression), myObjParam)

    Case ComparisonOperator.GreatherThanOrEqual
      filterExpression = Expression.Lambda(Of Func(Of PropertyType, Boolean))(Expression.GreaterThanOrEqual(myObjPropertyParam, myConstExpression), myObjParam)

    Case ComparisonOperator.LessThanOrEqual
      filterExpression = Expression.Lambda(Of Func(Of PropertyType, Boolean))(Expression.LessThanOrEqual(myObjPropertyParam, myConstExpression), myObjParam)
  End Select

EDIT:

Used Solution, gratie to Thomas Levesque and Jon Skeet )

  Dim expr As Expression = Nothing

  Select Case compOp
    Case ComparisonOperator.Contains
      expr = Expression.Call(myObjPropertyParam, "Contains", Nothing, constantExpression)
    Case ComparisonOperator.Different
      expr = Expression.NotEqual(myObjPropertyParam, constantExpression)
    Case ComparisonOperator.Equal
      expr = Expression.Equal(myObjPropertyParam, constantExpression)
    Case ComparisonOperator.GreatherThanOrEqual
      expr = Expression.GreaterThanOrEqual(myObjPropertyParam, constantExpression)
    Case ComparisonOperator.LessThanOrEqual
      expr = Expression.LessThanOrEqual(myObjPropertyParam, constantExpression)
  End Select

  filterExpression = Expression.Lambda(Of Func(Of PropertyType, Boolean))(expr, myObjParam)
  • 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-24T23:51:40+00:00Added an answer on May 24, 2026 at 11:51 pm

    There is no Contains operator (although there are methods named Contains). It would only make sense for some types (like String, collections and a few others), but not for others; for instance how would you define the Contains operator for integers or dates ?

    Now, if you want to apply the Contains method to a string via a lambda expression, you have to generate an expression that calls the method, using Expression.Call.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a stylesheet that makes use of exslt:dynamic module and more precisely, it
Should a highly dynamic website that is constantly generating new pages use a sitemap
It looks like #temptables created using dynamic SQL via the EXECUTE string method have
Say i need to filter a generic list with a dynamic query ( List<string>
I have the below enum that I use for one of my filters and
In past I use dynamic sql and datatable to get data from database. Such
Can I use dynamic data type in WF 4.0? And if this is possible
How do you build and use dynamic sql in a MySQL stored procedure?
Are there a real reason to use dynamic linking and binary distributions these days?
Is there any reason to use Dynamic Data Exchange (DDE) in a modern Windows

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.