Expression & lt; Func & lt; TObject, bool & gt; Difference from Func & lt; TObject, bool & gt;, functobject

Source: Internet
Author: User

Difference between Expression <Func <TObject, bool> and Func <TObject, bool>: functobject

Func <TObject, bool> YesDelegate(Delegate)

Expression <Func <TObject, bool> YesExpression

After Expression is compiled, it becomes delegate to run. For example

Expression <Func <int, bool> ex = x => x <100;

Func <int, bool> func = ex.Compile();

Then you can call func:

Func (5) //-returns true

Func (200) //-returns false

Expressions cannot be called directly.

======================================

Case: full database table query caused by incorrect query code.

The Code logic above is to dynamically generate a LINQ query Condition Based on the condition, and pass the Func type variable as a parameter to the Where method.

In fact, the parameter type required by Where is Expression <Func <TSource, bool>.

Solution:

Do not use Func <TSource, bool> or Expression <Func <TSource, bool>.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.