1 / 18

introducing LINQ

a tour of new features. introducing LINQ. Agenda of LINQ Presentation. LINQ Fundamentals Anonymous Functions/Lambda Expression Type Inference LINQ LINQ to SQL LINQ to XML LINQ to Entity. We have features for every step of the way. 1. LINQ Fundamentals.

dacian
Download Presentation

introducing LINQ

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. a tour of new features introducingLINQ

  2. Agendaof LINQ Presentation • LINQ Fundamentals • Anonymous Functions/Lambda Expression • Type Inference • LINQ • LINQ to SQL • LINQ to XML • LINQ to Entity We have features for every step of the way

  3. 1 LINQ Fundamentals Introduced in Visual Studio 2008 and .NET Framework version 3.5

  4. Getting Startedwith LINQ • Bridges the gap between world of objects and data. • Facilitates compile time type checking, and Intellisense • No need to learn different query language based on data source: SQL Database, XML documents, various web services, ADO.NET Datasets and any collection of objects that support IEnumerable<T> interface. All LINQ Query operation has three parts – Obtain the data source Create the Query Execute the query

  5. LINQ Queries Queries specifies what information to retrieve from the data source or sources. It also specifies how the information should be sorted, grouped, and shaped before it is returned. varquery_variable = from ****<data source> where ****<filter expression> select **** <type of returned elements> Query variables just stores the information that is required to produce results when query is executed at later point. Deferred Query Execution LINQ Queries and Query Operations Forcing Immediate Execution Developer can force execution by putting foreachloop immediately after query expression.

  6. Query Operations Standard Query Operators LINQ Queries and Query Operations Presents from, where, select and orderby clauses Presents Group By and Join clause

  7. Type Relationships in LINQ Query Operations Queries that do not transform source data. Queries that transform source data. LINQ Queries and Query Operations

  8. Benefits of LINQ This will cover the benefit of LINQ by using it in various scenarios covering LINQ to Object, LINQ to SQL, LINQ to XML.

  9. 2 Benefits of LINQ Access In-memory data structures, SQL (Datasets, Entities, and SQL), XML Documents

  10. LINQ to Objects LINQs to Object refers to the use of LINQ Queries with any Ienumerable or Ienumerable<T> collection directly, without the use of an intermediate LINQ provider (LINQ to SQL, LINQ to XML) More complex the operation you want to perform on data, the more benefit developer realizes. Advantage of LINQ over for each loops: More concise and readable, especially when filtering multiple conditions. Provide powerful filtering, ordering and grouping capabilities with a minimum of application code Can be porter to other data sources with little or no modification. Querying non-generic IEnumerable collection Explicitly declaration type of range variable is mandatory if using non-generic collection. Use of explicit declaration is equivalent to calling cast<TResult> method. Cast<TResult> will throw exception if the specified cast can not be performed. // C# var query = from Student s in arrList ... 'Visual Basic Dim query = From student As Student In arrList ...

  11. LINQ to Objects (File Directories) Query for a file with special attribute or name

  12. LINQ to Objects (Reflection) Query an assembly’s metadata with Reflection. This example uses the GetTypes method to return an array of types in the specified assembly. The where filter is applied so that only public types are returned. For each public type, a subquery is generated by using the MethodInfo array that is returned from the GetMethods call. These results are filtered to return only those methods whose return type is an array or else a type that implements IEnumerable<T>Finally, these results are grouped by using the type name as a key.

  13. LINQ to SQL LINQ to SQL run-time infrastructure and design-time tools significantly reduce the workload for the database application developer. LINQs to SQL provides a run-time environment for managing relational data as objects, without loosing the ability to query. It does this by tranlating LINQ queries to SQL for execution by the database, and then translating tabular results back into objects you define. LINQ to SQL Implement standard query operators for relational databases. Manages entity objects throughout their lifetime, aiding you in maintaining the integrity of your data Automating the process of translating your modification back into the store. DataContext is the main conduit for retrieving objects from database, and resubmit changes. First Step – Declaring object classes, for representing application data Discuss how Object Identity is maintained.

  14. LINQ to SQL Defining Relationships LINQ to SQL implements a technique called deferred loading in order to help maintain this illusion. When you query for an object you actually only retrieve the objects you asked for. The related objects are not automatically fetched at the same time. LINQs to SQL defines Association attribute you can apply to a member used to represent a relationship. An associate relationship is one like a foreign-key to primary-key relationship that is made by matching column values between tables. Querying Across Relationships

  15. LINQ to SQL Modifying and Saving Entities LINQs to SQL is also designed to offer maximum flexibility in manipulating and persisting changes made to your objects. When SubmitChanges() is called, LINQ to SQL automatically generates and executes SQL Commands in order to transmit the changes back to SQL database. Queries ????????

  16. LINQ to SQL Reuse a connection between ADO.NET Command and Data Context Performance can be improved by seeking read-only results by setting ObjectTrackingEnabled=false

  17. LINQ to SQL Entity Life Cycle Tracking Changes Submitting Changes Simultaneous Changes Transactions

  18. The End

More Related