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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:13:39+00:00 2026-06-13T05:13:39+00:00

So I have a query I’m constructing using Entity Framework, LINQ. Depending on the

  • 0

So I have a query I’m constructing using Entity Framework, LINQ. Depending on the search parameter, and the type of the parameter being searched.

I have created a function like this:

public static IQueryable<T> WhereInt<T>(this IQueryable<T> query, string propertyName, string contains)
        {
            var parameter = Expression.Parameter(typeof(T), "type");
            var propertyExpression = Expression.Property(parameter, propertyName);

            MethodInfo method = typeof(string).GetMethod("First");
            var someValue = Expression.Constant(contains, typeof(string));
            var containsExpression = Expression.Call(propertyExpression, method, someValue);

            return query.Where(Expression.Lambda<Func<T, bool>>(containsExpression, parameter));

        }

Used as such:

WhereInt(DCs, searchfield, search);

searchfield could be userid, username, integer or string, and ideally I want to do:

searchfield.value == search.toInt32()

sort of feature.

I want to also make DateTime types searchable too. Maybe I’ll make a WhereDateTime for that.

I get an error on var containsExpression = Expression.Call(propertyExpression, method, someValue);

This works fine with strings, but fails with the error:

Value cannot be null.
Parameter name: method
  • 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-06-13T05:13:40+00:00Added an answer on June 13, 2026 at 5:13 am

    There is no .First() method on an integer value. I really don’t know why you thought that would help you to generate an expression like searchfield.value == search.toInt32() (which doesn’t say First anywhere). Use an Equal expression instead.

    I think you’re looking for something more along these lines.

    public static IQueryable<T> WhereInt<T>(IQueryable<T> query, string propertyName, string value)
    {
        var parameter = Expression.Parameter(typeof(T), "type");
        var propertyExpression = Expression.Property(parameter, propertyName);
    
        var someValue = Expression.Constant(int.Parse(value), typeof(int));
        var containsExpression = Expression.Equal(propertyExpression, someValue);
    
        return query.Where(Expression.Lambda<Func<T, bool>>(containsExpression, parameter));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using in C# MYsql .I have query that works if I run
Let's say I have query structured like below which indicates dates search.asp?date=091210 I want
I have query which returns single value (i.e) count. I'm exceuting it using the
HI, I have query like this final Query contractQuery = cgnDao.getEntityManager(). createNativeQuery(SELECT k.phrase, ak.type
I have query to show the table like this: but I want to PIVOT
I have query with two MtM relations: $em = $this->getEntityManager(); $qb = $em->createQueryBuilder(); $qb
I have query table copyQuery which has Soil Condition has one of the columns,
I have query like this : SELECT EXTRACT(MONTH FROM d.mydate) AS synmonth, SUM(apcp) AS
Have this query: SELECT HOUR( DATE ) AS hr, COUNT( * ) AS cnt
I have a query that successfully grabs the unique products from my products table

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.