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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:43:10+00:00 2026-05-27T02:43:10+00:00

I am trying to dynamically generate linqtosql query using LinqKit . I would like

  • 0

I am trying to dynamically generate linqtosql query using LinqKit. I would like to check the field that I want to add for the prediction before sending the expression to LinqKit. So I have come up with some idea like

 Expression<Func<TResult, bool>> GetPrediction<TKey>
                            (Expression<Func<TResult, TKey>> selector, TResult input,  object value)
 {
    if(typeof(TKey) == typeof(string))
    {
         return selector.Invoke(input) == value; //Not working, how to covert here?
    }
    Throw new Exception("Type not supported");
 }

I am stuck at line 5, where I am supposed to generate an Expression<Func<TResult, bool>> and return. I know it’s possible but just have hard time to get the “click”

  • 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-27T02:43:11+00:00Added an answer on May 27, 2026 at 2:43 am

    I think you want something like:

    public static Expression<Func<TResult, bool>> GetPredicate<TKey>
        (Expression<Func<TResult, TKey>> selector, TResult input, object value)
    {
        // Note: Move "early out" here so that bulk of method is less deeply nested.
        // Really? Why make this generic in TKey then?
        if (typeof(TKey) != typeof(string))
        {
            throw new Exception("Type not supported");
        }
    
        var parameter = Expression.Parameter("input");
        var invocation = Expression.Invoke(selector, input);
        var constant = Expression.Constant(value);
        var equality = Expression.Equal(invocation, constant);
        return Expression.Lambda<Func<TResult, bool>>(equality, parameter);
    }
    

    I’m not quite sure what kind of equality that will use, mind you – it’s entirely possible it’s going to use a reference equality operation, whereas I suspect you want value equality. You’ll have to try it to see, being careful in tests due to string interning.

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

Sidebar

Related Questions

I'm trying to generate a query dynamically using textbox values from my Bookings form
Dear experts, I was trying to dynamically generate DOM elements using JS. I read
I'm trying to dynamically generate root folder in a url that's in the body
I am trying to dynamically generate content using JSP. I have a <c:forEach> loop
I'm trying to dynamically generate an image file that will be composed by other
In my .ascx usercontrol i'm trying to dynamically generate links using a value i've
TL;DR I'm trying to dynamically generate an asset URL using HTML5 data elements, on
I'm trying to generate graphs dynamically using JFreeChart as a result of some checkboxes
I'm trying to dynamically generate selectFields by mapping over mreq selectField using flip ,
I am trying to generate UITextField dynamically in place of UILabel. Now i want

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.