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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:07:28+00:00 2026-05-13T20:07:28+00:00

In following code is any difference when I put dl.DamageCount > 5 directly in

  • 0

In following code is any difference when I put “dl.DamageCount > 5” directly in the query or when I move “dl.DamageCount > 5” to a method or function then just call it from query?

It seems when I move it into a method, query does not work properly. Indeed it seems the function/method always return true regardless of condition evaluation. I’m using Linq-to-NHibernate.

 var q = from dl in session.Linq<DamageList>()
            where
            dl.DamageCount > 5
  • 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-13T20:07:28+00:00Added an answer on May 13, 2026 at 8:07 pm

    The best you can do is capture the predicate in an Expression<>. A method has already been compiled to IL and so isn’t able to be picked apart by a Linq provider.

    Expression<Func<DamageList, bool>> predicate = item => item.DamageCount > 5;
    

    You can then pass that predicate directly to Where:

    var q = session.Linq<DamageList>().Where(predicate);
    

    If you want to dynamically combine two such expressions, you either write the code for both into the one expression, or you capture both in separate expressions. This gets complicated because you need each one to refer to an item being passed in. This is really a different question, already asked: How do I dynamically create an Expression<Func<MyClass, bool>> predicate?

    You can write a compound predicate using the && oerator and still capture it in an expression:

    Expression<Func<DamageList, bool>> predicate = 
        dl => dl.DamageCount > 5 && dl.Name.Contains(criteria);
    

    You ask about calling methods in such an expression – well, that example does call a method!

    It builds a tree of Expression nodes of various types. Included somewhere will be a method call node, which says to call the Contains method of string (assuming Name is a string). So this is an example of a method call instruction embedded in an expression. In order for this to work, the Linq provider has to know what that method does, so it can turn it into the equivalent SQL (as would be the case for a typical ORM system).

    So you can embed certain standard method calls in expressions – it requires the Linq provider to know about them. The methods of string are well defined, but not every provider will necessarily be able to deal with all of them.

    It wouldn’t be impossible for a Linq provider to allow you to add your own extensions that handle extra methods, but I’m not aware of any that support that (obviously if the system is open source, you can add your own).

    To summarise – a Linq provider needs a tree of expression nodes that it can analyse to convert into some other language such as SQL, for execution in another context such as inside a remote database. If you write ordinary methods, the C# compiler will compile them into low-level executable IL, not expression nodes. So that is like a dead-end: there’s no built-in facility for turning IL back into expression nodes.

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

Sidebar

Ask A Question

Stats

  • Questions 380k
  • Answers 380k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Maybe this is what you are looking for? SELECT all_wins.team_id,… May 14, 2026 at 9:46 pm
  • Editorial Team
    Editorial Team added an answer Posting this in hopes that it will help others. At… May 14, 2026 at 9:46 pm
  • Editorial Team
    Editorial Team added an answer By bypassing staging and making changes in production is a… May 14, 2026 at 9:46 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.