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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:00:10+00:00 2026-05-24T08:00:10+00:00

I am trying to dynamically create a linq expression with the contains operator. After

  • 0

I am trying to dynamically create a linq expression with the contains operator.

After reading several posts related to this topic, I have come up with the following code that allows me to perform a “contains” like evaluation:

internal static Expression<Func<TEntity, bool>> StringContains<TEntity>(string propertyName, string subString)
{
    MethodInfo contains = typeof(JsonLinqParser_Paser).GetMethod("Like");
    var param = Expression.Parameter(typeof(TEntity));
    var body = Expression.Call(contains, Expression.Property(param, propertyName), Expression.Constant(subString, typeof(string)));

    var lambda = Expression.Lambda<Func<TEntity, bool>>(body, param);

    return lambda;
}
public static bool Like(string a, string b)
{
    return a.Contains(b);
}

And this is called like so:

var expression = Expression.Lambda<Func<TEntity, bool>>(StringContains<TEntity>("FIPSCO_STR", _myStringValue), param);

However, at runtime, I get an error as follows:

Expression of type
‘System.Func`2[DAL.BestAvailableFIP,System.Boolean]’ cannot be used
for return type ‘System.Boolean’

where “DAL.BestAvailableFIP” is the “TEntity” type.

I’m sure this is all related to my lack of knowledge regarding lambda expressions. Can anyone tell me what I’m doing wrong?

  • 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-24T08:00:10+00:00Added an answer on May 24, 2026 at 8:00 am

    StringContains already returns a LambdaExpression.

    You shouldn’t put it in another lambda expression.
    If you want to create another lambda expression that contains it, you should use its Body.

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

Sidebar

Related Questions

I am trying to dynamically create a linq expression at runtime using PredicateBuilder from
I'm trying to dynamically create buttons at runtime with PyQT4.7 However, this being my
I'm trying to dynamically create this function: svg.path($('#shape23'), path.move(333,410) .smoothC(333,410,333,410) .smoothC(217.5,415.75,217.5,415.75) .smoothC(333,500,333,500) .close(), {fill:
I'm trying to dynamically create a form using JQuery. In order to do this,
I'm trying to dynamically create a datatemplate for a listbox. This is for a
I am trying to create the following Where clause expression dynamically: context.Cars. Where(c =>
I'm trying to dynamically create an object of a certain type in a LINQ-to-XML
I'm trying to dynamically create a set of labels in my XUL Runner application.
I'm trying to dynamically create a connection string during compile time: private static string
I'm trying to dynamically create a book from code server-side. That part's working fine,

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.