LINQ dynamic Microsoft Query Library

Source: Internet
Author: User

LINQ is a new feature of. NET Framework 3.5. It is a feature integrated into the language. With it, we can easily query data. For the average person, pay more attention to the LINQ-SQL, It is a. net in the better use of An ORM tool.

Now, go to the topic. Normally, we use a strong type when writing a LINQ query. That is to say, during compilation, we can check whether the types match, this avoids the risk of Type mismatch in many runtimes. Because of this, we did not write SQL statements as "convenient" (the cost is dangerous) when writing a LINQ query statement, especially when we have many dynamic filters, it is even more troublesome to write it in a LINQ statement.

Now we can use the dynamic query library to solve this problem. It defines some extension methods so that we can use string expression directly to achieve condtion-where and sort-orderby (previously, we used to use LINQ expression ). For example:

Code
Dataclasses1datacontext CTX =   New Dataclasses1datacontext ();
VaR Query = CTX. Tests. Where ( " Id> @ 0 and ID <@ 1 " , 5 , 10 ). Select ( " New (ID) " );

Is this more convenient?

The usage of the LINQ dynamic query library is as follows:

1) download the library

VB. NET Edition
C # Edition

2) Take C # as an example to copy the dynamic source file in the dynamicquery folder to your project.

3) add the "using system. LINQ. Dynamic;" namespace so that you can use it.

 

Have a happy day!

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.