Hello frnds today I will explain you what is linq and what
is advantage over simple sql query and how to use linq query so lets start with it
Introduction :
Linq is stands for
Language Integrated Query its named because it looks very similar to c# .With
the help of linq we can access various data sources like database and XML .Normally
linq expression uses lambda expression
to execute query statement .It works in similar
manner as just like sql query structure .It
start with from keyword . Linq has own it query processing engine .Basically it
follows the concept of class and objects .It treats data-sources as object ,rather than a data base .
Advantages over Sql:
Easy to understand
Language behavioral
Check at compile time rather than runtime
Basic Syntax Example for Linq Structure :
The code shown
below stores the names in an array then selects the names that starts with S.
string[] names={ "Sandeep" ,"Ram","Shobha","Sonali"};
var shortName=from name in names
where name.StartsWith("S")
select name;
foreach(string sname in shortName)
Console.WriteLine("Short Name {0}",sname);
Console.ReadLine();
string[] names={ "Sandeep" ,"Ram","Shobha","Sonali"};
var shortName=from name in names
where name.StartsWith("S")
select name;
foreach(string sname in shortName)
Console.WriteLine("Short Name {0}",sname);
Console.ReadLine();
The
above code will print all the name starts with
“S” in array format .So it is more expressive way to selecting the names
than if we had to write code without
using LINQ .
Output :
So this is the basic structure of linq to understand .In further
articles I will explain you more uses of linq and use with database.
Thanks I hope it will helpful for u














