Introduction to LINQ
1. Net Language Integrated Query (LINQ): a general solution is used to address access and integration of various information sources, instead of a proprietary solution specific to relational databases or XML.
2. In LINQ, the query becomes Programming Language This allows the query expression to get a good syntax check during compilation, rich metadata, and SMART awareness of the benefits of other strong languages.
Syntax format:
Class Program
{
Static Void Main ( String [] ARGs)
{
String [] Names = { " Burke " , " Connor " , " Frank " , " Everett " , " Albert " , " Geroge " , " Harris " , " David " } ;
Ienumerable < String > Query = From S In Names
Where S. Length = 5
Orderby s
Select S. toupper ();
Foreach ( String Item In Query)
{
Console. writeline (item );
}
Console. Readline ();
}
}
Above:
Ienumerable < String > Query = From S In Names
Where S. Length = 5
Orderby s
Select S. toupper ();
Equivalent
Ienumerable < String > Query = From S In Names
Where (S => S. Length = 5)
Orderby (S => S)
Select (S => S. toupper ());
Equivalent to the following Commission: Func < String , Bool > Filter = Delegate ( String S) {
ReturnS. Length= 5;}
Func < String , String > Extract = Delegate ( String S) {
ReturnS ;}
Func < String , String > Project = Delegate ( String S) {
ReturnS. toupper ();} ;
Ienumerable < String > Query = Names. Where (filter)
. Orderby (extract)
. Select (project );