3. TopicsTopics
• What is LINQ
• Queries without LINQ
• Key features of LINQ
• LINQ Architecture
• LINQ to…
4. Technology developed byTechnology developed by
Anders HejlsbergAnders Hejlsberg
& friends at Microsoft& friends at Microsoft
(2005)(2005)
Language Integrated QueryLanguage Integrated Query
(LINQ)(LINQ)
1.1. Unified Programming Model For Querying Any kind of Data Sources.Unified Programming Model For Querying Any kind of Data Sources.
2.2. Common Data Access Model For all kinds of Data Sources.Common Data Access Model For all kinds of Data Sources.
3.3. Included as part of .NET Framework 3.5Included as part of .NET Framework 3.5
5. Language-Integrated Query (LINQ) brings query capabilities into the C#
language itself
Traditionally developers had to learn a primary programming language,
such as C#, and a secondary language, such as SQL or X-Query.
Now, instead of learning a separate query language, you can use your
knowledge of C#, together with some additional keywords and concepts,
to query SQL databases, ADO.NET datasets, XML documents, and any
.NET collection class that implements the I-Enumerable interface.
6. Queries without LINQQueries without LINQ
foreach(Customer c in customers)
if (c.Region == "USA") ...
• Objects using loops and conditions
//Customers/Customer[@Region='USA']
• XML using XPath/XQuery
SELECT * FROM Customers WHERE
Region='USA'
• SELECT from database tables
7. Key Features Of LINQKey Features Of LINQ
1. Query Expressions
2. Lambda Expressions
3. New Keyword Usage
4. Object Initialization & Anonymous Type
5. Extension Methods
6. Partial Methods
7. Null able Value Types
8. XML Enhancements
9. Expression Trees.
8. LINQ-GENERAL-SYNTAXLINQ-GENERAL-SYNTAX
var contacts =
from c in customers
where c.City == "Hove"
select new { c.Name, c.Phone };
var contacts =
customers
.Where(c => c.City == "Hove")
.Select(c => new { c.Name, c.Phone });
Extension
methods
Lambda
expressions
Query
expressions
Object
initializers
Anonymous
types
Local variable
type inference