What is Linq
Linq is short for Language Integrated Query. If you are used to using SQL to query databases, you are going to have something of a head start with Linq, since they have many ideas in common. Before we dig into Linq itself, let’s step back and look at what makes SQL different from C#.
Syntax
- var lQuery = from < object > in < table_Name or List_Name > where < object > . < column_name > < relational operator > < Condition_to_satisfied > select < object > . < column_name > ;
- Var lQuery=from o in Orders
- where o.CustomerID == 84
- select o.Cost;
Note that you can perform whatever computation you wish inside the anonymous type initializer.
eg
- var lQuery= from o in Orders
- where o.CustomerID == 84 select new { o.OrderID, o.Cost, CostWithTax = o.Cost * 10 };
eg
- var lQuery= from o in Orders
- where o.CustomerID == 84 && o.Cost > 100
- select new { o.OrderID, o.Cost, CostWithTax = o.Cost * 10 };
This is achieved by using the new “orderby” keyword.
eg
- var lQuery= from o in Orders
- where o.CustomerID == 84
- orderby o.Cost ascending
- select new { o.OrderID, o.Cost };
- var Found = from o in Orders
- where o.CustomerID == 84
- orderby o.Cost descending select new { o.OrderID, o.Cost };
It is achieved by using the “from” keyword multiple times.
eg
- var lQuery = from o in Orders
- from c in Customers
- where o.CustomerID == c.CustomerID
- select new { c.Name, o.OrderID, o.Cost };
A list of matching objects,
eg
- // Group orders by customer.
- var lQuery = from o in Orders
- group o.Cost by o.CustomerID;
- // Iterate over the groups.
- foreach(var Cust in lQuery)
- {
- // About the customer…
- Console.WriteLine(“Customer with ID” + Cust.Key.ToString() + ”ordered” + Cust.Count().ToString() + ”items.”);
- // And the costs of what they ordered.
- foreach(var Cost in Cust)
- Console.WriteLine(”Cost: ” + Cost.ToString());
- }

Frank Núñez RodríguezPosted May 6, 2015, 3:15 PM
var query = from o in Orders join c in Customers on o.CustomerID equals c.CustomerID select new {c.Name, o.OrderID, o.Cost };
Frank Núñez RodríguezPosted May 6, 2015, 3:12 PM
Hello It articulates is very good one to begin to learn. But I want to add you alone a part for selection of multiple charts that one can also make this way: