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 4257382
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:30:16+00:00 2026-05-21T05:30:16+00:00

i am leveraging this project to use jqgrid to filter and sort collections .

  • 0

i am leveraging this project to use jqgrid to filter and sort collections. The one issue i see if that, when looping through the collection and checking the property of a string field is null, this code below will blow up. i want to tweak the code below so it creates a lambda that not only does a “ToString()” and “Contains” but also support if a property is null (and treats it as string.empty)

I basically have 2 inputs into this function below:

  1. FieldName
  2. Data Value

and the code below is dynamically building up an expression to loop through a collection and check “Contains” against the property that maps onto the FieldName being passed in.

i have code that looks like this:

        ParameterExpression parameter = Expression.Parameter(query.ElementType, "p");

        MemberExpression memberAccess = null;
        MethodCallExpression memberAccessToString = null;
        foreach (var property in column.Split('.'))
        {
            memberAccess = MemberExpression.Property(memberAccess ?? (parameter as Expression), property);
            memberAccessToString = MemberExpression.Call(memberAccess, "ToString", new Type[] {}, new Expression[] {});
        }

        Expression condition = null;
        LambdaExpression lambda = null;
            case WhereOperation.Contains:
                condition = Expression.Call(memberAccessToString,
                    typeof(string).GetMethod("Contains"),
                    Expression.Constant(value));
                lambda = Expression.Lambda(condition, parameter);

        MethodCallExpression result = Expression.Call(
               typeof(Queryable), "Where",
               new[] { query.ElementType },
               query.Expression,
               lambda);

        return query.Provider.CreateQuery<T>(result);
  • 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-21T05:30:16+00:00Added an answer on May 21, 2026 at 5:30 am

    Have you checked Expression.Coalesce you could apply it to memberAccess before calling ToString()

    memberAccess = MemberExpression.Property(memberAccess ?? (parameter as Expression), property);
    memberAccessToString = MemberExpression.Call(Expression.Coalesce(memberAccess,Expression.Constant(string.Empty)), "ToString", new Type new Type[] {}, new Expression[] {});
    

    Didn’t test it but may lead to the solution

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

Sidebar

Related Questions

I am working on a project that is going to use CouchDB for flexible
I want to use Powershell to write some utilities, leveraging our own .NET components
I have a project that I have recently started working on seriously but had
In a project that I've been involved with for many years, I've gradually evolved
Hudson CI server displays stability weather which is cool. And it allows one project
I'm leveraging the Doubleton Pattern from the Doubleton Design Pattern on Code Project in
Looking for a little advice on leveraging AsParallel() or Parallel.ForEach() to speed this up.
Google Maps seems to be able to do this quite well, presumably leveraging my
I have an app leveraging Core Data SQLITE3 that works perfectly in the simulator.
I am interested in leveraging F#'s strengths in the area of parallelism into an

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.