LINQ

569 views
441 views

Published on

Introduction about .NET LINQ API and all it's components.

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
569
On SlideShare
0
From Embeds
0
Number of Embeds
7
Actions
Shares
0
Downloads
35
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

LINQ

  1. 1. www.getgroup.com © Copyright by GET Group 2010 1 Language INtegrated Query
  2. 2. 2 LINQ  Introduction. Components.  Standard Query Operators  Language Extensions         Query syntax. Implicitly typed variables. Anonymous types. Object Initializer. Lambda expressions. Extension Methods. Partial Methods. Providers    LINQ to Object. LINQ to XML. LINQ to ADO.NET         www.getgroup.com © Copyright by GET Group 2010  LINQ to Dataset. LINQ to SQL. LINQ to Entities. LINQ to ???? PLINQ. Performance. Pros and Cons. Examples. 2
  3. 3. www.getgroup.com © Copyright by GET Group 2010 3
  4. 4. www.getgroup.com © Copyright by GET Group 2010 4
  5. 5. www.getgroup.com © Copyright by GET Group 2010 5
  6. 6. 6 Introduction  LINQ APIs unifies the query experience across all sorts of data domains, allowing developers to learn a single query language that’s integrated within the .NET Framework.  Query on Sequence to get Element(s). www.getgroup.com © Copyright by GET Group 2010  Declarative V.S Imperative Programming.
  7. 7. www.getgroup.com © Copyright by GET Group 2010 7 Components
  8. 8. 8 Restriction Aggregate Projection Quantifiers Partitioning Generation Join Standard Query Operators Concatenation Equality Ordering Conversion Grouping Set www.getgroup.com © Copyright by GET Group 2010 Element
  9. 9. 9 Query syntax  Dot notation syntax "Fluent”  Mixed www.getgroup.com © Copyright by GET Group 2010  Query Expression “List Comprehensions or Functional Programming”.
  10. 10. www.getgroup.com © Copyright by GET Group 2010 10
  11. 11. www.getgroup.com © Copyright by GET Group 2010 11
  12. 12. 12  Query expressions are not actually evaluated until you iterate over the sequence "Lazy Evaluation”.  Apply the same LINQ query multiple times to the same container, and rest assured you are obtaining the latest and greatest results.  In some cases it’d cause performance troubles from accessing data sources so many times. www.getgroup.com © Copyright by GET Group 2010 Deferred Execution
  13. 13. 13 Immediate Execution  ToArray(), ToList(), ToDictionary(), ToLookUp().  Useful in not accessing data source so many times, but take memory factor into consideration. www.getgroup.com © Copyright by GET Group 2010  Via non-deferred conversion operators.
  14. 14. 14 Language Extensions Implicitly typed variables. Anonymous types. Object Initializer. Lambda expressions. Extension Methods. Partial Methods. Expression Tree. www.getgroup.com © Copyright by GET Group 2010 Query syntax.
  15. 15. www.getgroup.com © Copyright by GET Group 2010 15
  16. 16. 16  More efficient if you plan on allowing many potentially unimplemented methods in the code.  LINQ to SQL and Entity Framework. www.getgroup.com © Copyright by GET Group 2010 Partial Methods
  17. 17. 17  Data representation of a piece of code.  Span multiple data domains. www.getgroup.com © Copyright by GET Group 2010 Expression Tree
  18. 18. www.getgroup.com © Copyright by GET Group 2010 18 Providers
  19. 19. 19 LINQ to Objects  Perform queries on memory objects.  Collections  Parallelizable ”Using PLINQ”. www.getgroup.com © Copyright by GET Group 2010  Generic and Non Generic.
  20. 20. www.getgroup.com © Copyright by GET Group 2010 20
  21. 21. www.getgroup.com © Copyright by GET Group 2010 21
  22. 22. 22 LINQ To Dataset  LINQ To Objects.  Perform set operations on sequences of DataRow objects.  Retrieve and set DataColumn values. DataTable so Standard Query Operators may be called.  Copy modified sequences of DataRow objects to a DataTable. www.getgroup.com © Copyright by GET Group 2010  Obtain a LINQ standard IEnumerable<T> sequence from a
  23. 23. www.getgroup.com © Copyright by GET Group 2010 23
  24. 24. 24 LINQ To SQL  Query a relational Microsoft SQL Server database.  Offering you an object model based on available entities.  Query this object model by using LINQ queries that are automatically converted into corresponding SQL queries by the LINQ to SQL engine. www.getgroup.com © Copyright by GET Group 2010  Working with SQL Server databases in the current world of object-oriented programming languages.
  25. 25. www.getgroup.com © Copyright by GET Group 2010 25
  26. 26. 26 ADO.NET Entity Framework  The ADO.NET Entity Framework provides a mapping from the relational database schema to objects.  Object-relational mapping (ORM) framework for the .NET Framework.  SQL Server and Third-Party Providers.  Entity Data Model (edmx).   Conceptual Schema Definition Language (CSDL). Entities. ➤ Mapping — Mapping from .NET classes to relational tables and associations.  Mapping Specification Language (MSL). ➤ Logical — Relational data.   Store Schema Definition Language (SSDL). POCO allows you to write your own entity classes in a persistence ignorant fashion. www.getgroup.com © Copyright by GET Group 2010 ➤ Conceptual —.NET classes.
  27. 27. www.getgroup.com © Copyright by GET Group 2010 27
  28. 28. 28  Looks like LINQ To SQL.  Except some syntax differences. www.getgroup.com © Copyright by GET Group 2010 LINQ To EF
  29. 29. 29 LINQ To SQL or EF LINQ To SQL EF Model Domain Model Conceptual Data Model Database Supported SQL Varity of DB Query • LINQ To SQL • Data Context • LINQ To Entities • Object Services • Entity Client Future Improvements No Yes Generate database from entity model No Yes Database Schema changed synchronization No Yes www.getgroup.com © Copyright by GET Group 2010 Feature
  30. 30. 30  WPF, Silverlight, WWF and WCF make use of XML.  System.XML Document. “Bottom up”  LINQ To XML APIS. “Top-down code” www.getgroup.com © Copyright by GET Group 2010 LINQ To XML
  31. 31. 31 LINQ To ????  LINQ To Events “RX Framework”.  LINQ To Files. www.getgroup.com © Copyright by GET Group 2010  LINQ To Form Controls.
  32. 32. www.getgroup.com © Copyright by GET Group 2010 32
  33. 33. 33 PLINQ  LINQ query that will perform its workload in parallel (if possible).  Based on new TPL. “ Task Parallel Library” Partitioning the work into tasks, Executing those tasks on threads, Collating the results into a single output sequence.  At run time:  Parallel, Sequential.  Expensive parallel, Inexpensive sequential. www.getgroup.com © Copyright by GET Group 2010  Automates all the steps of parallelization,
  34. 34.  Degree of parallelism.  Token Cancellation.  With Execution Mode www.getgroup.com © Copyright by GET Group 2010 34
  35. 35. www.getgroup.com © Copyright by GET Group 2010 35 Performance
  36. 36. www.getgroup.com © Copyright by GET Group 2010 36
  37. 37. www.getgroup.com © Copyright by GET Group 2010 37
  38. 38. www.getgroup.com © Copyright by GET Group 2010 38
  39. 39. www.getgroup.com © Copyright by GET Group 2010 39
  40. 40. www.getgroup.com © Copyright by GET Group 2010 40
  41. 41. www.getgroup.com © Copyright by GET Group 2010 41
  42. 42. 42                  Professional C# 4 and .NET 4 book. Sams C# Unleashed C# 4 book. Oreilly Csharp 4.0 in a Nutshell book. Apress Pro LINQ book. Microsoft Press Programming LINQ in NET Framework 4 book. Concurrent Programming on Windows book. LINQ To Events. POCO I. POCO II. POCO III. Performance l. Performance ll. Performance lll. Performance IV. LINQ To RX. LINQ Providers List. LINQ To SQL V.S EF. www.getgroup.com © Copyright by GET Group 2010 References

×