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!