LINQ Dynamic 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 nice 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.