Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to LINQ Lecture # 19 August 2 2013. Introduction How do you interrogate/manipulate data? What if you could do the work in a type-safe," string-free.

Similar presentations


Presentation on theme: "Introduction to LINQ Lecture # 19 August 2 2013. Introduction How do you interrogate/manipulate data? What if you could do the work in a type-safe," string-free."— Presentation transcript:

1 Introduction to LINQ Lecture # 19 August 2 2013

2 Introduction How do you interrogate/manipulate data? What if you could do the work in a type-safe," string-free manner? What if you could use a consistent querying syntax for data, objects or XML?

3 Agenda What is LINQ Queries without LINQ Key features of LINQ LINQ Architecture LINQ to…

4 Introduction We use many different types of query – SQL, XQuery/XPath, DataView row filters, etc. Maybe we could enhance productivity by... – Deciding on one query expression syntax – Enabling compilers to check queries & results – Allow extensibility to target all kinds of data

5 What is LINQ? Language Integrated Query Make query a part of the language Component of.NET Framework 3.5

6 Queries 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 Language Innovations 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

8 Key Features of LINQ Delayed Execution  LINQ queries don't execute until they must Retrieve specific values Iterate through the collection Perform an operation Write Data Access Code directly Compile time syntax and schema checking (intellisense too) no need of inline sql or to wait until runtime to see if it is ok LINQ data access code abstracted from underlying data consistent syntax across various data sources can join information from different sources.

9 Architecture Compilers (language-level support) Standard Query Operators Expression Trees Linq-enabled data sources Linq to objects Linq-enabled ADO.NET Linq to SQL (DLinq) Linq to datasets Linq to entities Linq to XML (XLinq)

10 LINQ to… LINQ to Objects LINQ to SQL (formerly known as DLINQ) LINQ to XML (formerly known as XLINQ) LINQ to Entities (ADO.NET Entities)

11 LINQ to Objects Query any IEnumerable source Includes arrays, List, Dictionary... Many useful operators available Sum, Max, Min, Distinct, Intersect, Union Expose your own data with IEnumerable or IQueryable Create operators using extension methods

12 New Language Features – LINQ to objects

13 LINQ to SQL (formerly known as DLinq) Object-relational mapping (ORM)  Records become strongly-typed objects.  Includes tracking of changed objects and persistence.  Ensures that you will not obtain multiple objects for the same underlying row in the database ( Fowler’s Identity Map) Data context is the controller mechanism Facilitates update, delete & insert Type, parameter and injection safe

14 LINQ to SQL

15 LINQ to XML (formerly known as XLinq) Similar to LINQ to SQL but along the idea of querying XML documents using LINQ syntax rather than the XPath/XQuery syntax.

16 LINQ to XML

17 LINQ to Entities LINQ to Entities (ADO.NET Entities)  A more advanced ORM solution that allows more extensive mapping and manipulation between how the object appears and the underlying data source.  LINQ to Entity provides Excellent build support; if it isn't mapped 100%, it won't build It works with other databases (I'm currently using it with Oracle) It properly seperates the structural model from the conceptual entity model. It maps many to many relationships properly.

18 LINQ to Entities

19 Summary Had a quick intro on  LINQ and its need  Key Language features  LINQ Architecture  LINQ Types  LINQ Operators

20 For more information…. Official sitehttp://msdn.microsoft.com/en-us/netframework/aa904594.aspx Tutorialshttp://weblogs.asp.net/scottgu/archive/tags/LINQ/default.aspx 101 LINQ Sampleshttp://msdn.microsoft.com/en-us/vcsharp/aa336746.aspx LINQ Padhttp://www.linqpad.net/


Download ppt "Introduction to LINQ Lecture # 19 August 2 2013. Introduction How do you interrogate/manipulate data? What if you could do the work in a type-safe," string-free."

Similar presentations


Ads by Google