Presentation is loading. Please wait.

Presentation is loading. Please wait.

A tour of new features introducing LINQ. Agenda of LINQ Presentation We have features for every step of the way LINQ Fundamentals Anonymous Functions/Lambda.

Similar presentations


Presentation on theme: "A tour of new features introducing LINQ. Agenda of LINQ Presentation We have features for every step of the way LINQ Fundamentals Anonymous Functions/Lambda."— Presentation transcript:

1 a tour of new features introducing LINQ

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

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

4 All LINQ Query operation has three parts – 1.Obtain the data source 2.Create the Query 3.Execute the query 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 interface. Getting Started with LINQ

5 LINQ Queries and Query Operations 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. var query_variable = from **** where **** select **** Query variables just stores the information that is required to produce results when query is executed at later point. Deferred Query Execution Forcing Immediate Execution Developer can force execution by putting foreach loop immediately after query expression.

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

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

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

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

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

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 Finally, these results are grouped by using the type name as a key.

13 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 LINQ to SQL run-time infrastructure and design-time tools significantly reduce the workload for the database application developer. First Step – Declaring object classes, for representing application data DataContext is the main conduit for retrieving objects from database, and resubmit changes. Discuss how Object Identity is maintained. LINQ to SQL 1.Implement standard query operators for relational databases. 2.Manages entity objects throughout their lifetime, aiding you in maintaining the integrity of your data 3.Automating the process of translating your modification back into the store.

14 LINQ to SQL Defining Relationships 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 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.

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. Queries ???????? When SubmitChanges() is called, LINQ to SQL automatically generates and executes SQL Commands in order to transmit the changes back to SQL database.

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


Download ppt "A tour of new features introducing LINQ. Agenda of LINQ Presentation We have features for every step of the way LINQ Fundamentals Anonymous Functions/Lambda."

Similar presentations


Ads by Google