• Like
  • Save
C# LINQ
Upcoming SlideShare
Loading in...5
×

C# LINQ

  • 1,418 views
Uploaded on

 

More in: Education , Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
1,418
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
0
Comments
0
Likes
2

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. LINQWhat is LINQ?Introduction to LINQLINQ Example
  • 2. Language Integrated Query Language-Integrated Query (LINQ) is an innovation introduced in Visual Studio 2008 and .NET Framework version 3.5 that bridges the gap between the world of objects and the world of data. Traditionally, queries against data are expressed as simple strings without type checking at compile time or IntelliSense support. Furthermore, you have to learn a different query language for each type of data source: SQL databases, XML documents, various Web services, and so on. LINQ makes a query a first-class language construct in C# and Visual Basic. You write queries against strongly typed collections of objects by using language keywords and familiar operators.
  • 3. Language Integrated Query
  • 4. Introduction to LINQ Queries A query is an expression that retrieves data from a data source. Queries are usually expressed in a specialized query language. Different languages have been developed over time for the various types of data sources, for example SQL for relational databases and XQuery for XML. In a LINQ query, you are always working with objects. You use the same basic coding patterns to query and transform data in XML documents, SQL databases, ADO.NET Datasets, .NET collections, and any other format for which a LINQ provider is available
  • 5. Example LINQ to Collections class IntroToLINQ { static void Main() { int[] numbers = new int[7] { 0, 1, 2, 3, 4, 5, 6 }; // 2. Query creation. var numQuery = from num in numbers where (num % 2) == 0 orderby num descending select num; // 3. Query execution. foreach (int num in numQuery) { Console.Write("{0,1} ", num); } }}
  • 6. Advantages of LINQ  Unified data access Single syntax to learn and remember  Strongly typed Catch errors during compilation  IntelliSense Prompt for syntax and attributes  Bindable result sets
  • 7. LINQ ArchitectureC# VB.NET Others.NET Language Integrated Query (LINQ) LINQ data source providers ADO.NET support for LINQLINQto LINQ LINQ LINQ LINQObjects to Datasets to SQL to Entities to XML
  • 8. LINQ to SQL  Object-relational mapping Records become strongly-typed objects  Data context is the controller mechanism  Facilitates update, delete & insert  Translates LINQ queries behind the scenes  Type, parameter and injection safe
  • 9. Database mapping  VS 2008 designer or SQLMetal command  Map tables & fields to classes & properties  Generates partial classes with attributes  Each record becomes an object  Data context represents the database  Utilize tables, views or stored procedures
  • 10. Modifying objects  Update Set object properties  Delete context.Table.DeleteOnSubmit(object)  Insert context.Table.InsertOnSubmit(object)  Commit changes back context.SubmitChanges() Transactional - all or nothing