What is linq
Download
1 / 29

What is LINQ? - PowerPoint PPT Presentation


  • 148 Views
  • Uploaded on

What is LINQ?. Language Integrated Query Make query a part of the language Component of .NET Framework 3.5 Shipped with Visual Studio 2008.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' What is LINQ?' - eden


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
What is linq
What is LINQ?

  • Language Integrated Query

  • Make query a part of the language

  • Component of .NET Framework 3.5

  • Shipped with Visual Studio 2008


  • Linq is short for Language Integrated Query. If you are used to using SQL to query databases, you are going to have something of a head start with Linq, since they have many ideas in common.



  • Language Integrated Query and emulates the query operations of the relational model. (LINQ, pronounced "link") is a Microsoft.NET Framework component that adds native data querying capabilities to .NET languages.



LINQ evolution of data access. It is a programming model that brings a much needed uniformity to accessing data from files, XML, database, registry, event log

  • Allows to perform iterations on Collections

  • Main namespace is System.core


Query with linq
Query with LINQ evolution of data access. It is a programming model that brings a much needed uniformity to accessing data from files, XML, database, registry, event log

C#var myCustomers = from c in customers where c.Region == "UK" select c;


Advantages
Advantages evolution of data access. It is a programming model that brings a much needed uniformity to accessing data from files, XML, database, registry, event log

  • Unified data accessSingle syntax to learn and remember

  • Strongly typedCatch errors during compilation

  • IntelliSensePrompt for syntax and attributes

  • Bindable result sets

  • More evident when more complex filters are present


Architecture
Architecture evolution of data access. It is a programming model that brings a much needed uniformity to accessing data from files, XML, database, registry, event log

C#

VB.NET

Others

.NET Language Integrated Query (LINQ)

LINQ data source providers

ADO.NET support for LINQ

LINQto Objects

LINQto Datasets

LINQto SQL

LINQto Entities

LINQto XML


Linq to objects
LINQ to Objects evolution of data access. It is a programming model that brings a much needed uniformity to accessing data from files, XML, database, registry, event log

  • C#int[] nums = new int[] {0,4,2,6,3,8,3,1};double average = nums.Take(6).Average();var above = from n in nums where n > average select n;

  • Filtering process is easy because of the Intellisense feature


Linq to objects1
LINQ to Objects evolution of data access. It is a programming model that brings a much needed uniformity to accessing data from files, XML, database, registry, event log

  • Use of Ienumerable <T> or Iqueryable<T> collection

    • Query any IEnumerable<T> sourceIncludes arrays, List<T>, Dictionary...

  • Instead of for each loops or iterative loops the condition of LINQ used along with Ienumerable helps in rapid data retrieval


  • Linq operators
    LINQ operators evolution of data access. It is a programming model that brings a much needed uniformity to accessing data from files, XML, database, registry, event log

    and many others


    Linq to dataset
    LINQ to Dataset evolution of data access. It is a programming model that brings a much needed uniformity to accessing data from files, XML, database, registry, event log

    • LINQ to dataset is build on the top of ADO.Net to simplify the tasks

    • Ensure that a reference System.Data.DataSetExtensions.dll is added

    • Typed dataset feture is present(Fields)

    • Reshaping data with Anonymous type feature


    Linq to entities
    LINQ to Entities evolution of data access. It is a programming model that brings a much needed uniformity to accessing data from files, XML, database, registry, event log

    • What is the Entity Data Model?

      Definition for your application model

      Map between app model, database schema

      Advanced mapping scenarios supported

      One entity mapped across multiple tables

      • Multiple inheritance hierarchy mappings

      • Many-to-many without "link" table in model


    Linq to entities or linq to sql
    LINQ to Entities or LINQ to SQL? evolution of data access. It is a programming model that brings a much needed uniformity to accessing data from files, XML, database, registry, event log

    • LINQ to SQL

      • Shipped with Visual Studio 2008 and .NET 3.5

      • Emphasis on rapid application development

      • Supports Microsoft SQL Server family of databases

    • LINQ to Entities

      • Will ship as an update to .NET 3.5

      • Offers a provider model for third-party databases

      • Designed for enterprise-grade data scenarios

      • Higher level of abstraction for programming databases

      • Just one layer of the overall ADO.NET Entity Framework


    Linq to entities generating queries
    LINQ to Entities: Generating Queries evolution of data access. It is a programming model that brings a much needed uniformity to accessing data from files, XML, database, registry, event log

    • Converting LINQ queries to SQL

      • Compiler converts code into a LINQ expression tree

      • LINQ to Entities converts LINQ expression tree into a DbCommandTree based on mapping information

      • DbCommandTree expressed in terms of the database schema

      • ADO.NET provider generates a DbCommand

      • LINQ to Entities executes the DbCommand, assembles results into the structure(s) specified in the LINQ query


    Entity framework query options
    Entity Framework Query Options evolution of data access. It is a programming model that brings a much needed uniformity to accessing data from files, XML, database, registry, event log

    • EntityClient Provider

    string"SELECT VALUE o FROM NorthwindEntities.Orders AS o " +

    "WHERE o.Customers.CustomerID = 'ALFKI'";

    EntityCommandnewEntityCommand(eS

    EntityDataReader =

    while (

    Console. ("{0} {1:d}", ["OrderID"], ["OrderDate"]);


    Linq to sql
    LINQ to SQL evolution of data access. It is a programming model that brings a much needed uniformity to accessing data from files, XML, database, registry, event log

    • Object-relational mappingRecords 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


    • Instead of manipulating the database evolution of data access. It is a programming model that brings a much needed uniformity to accessing data from files, XML, database, registry, event logdirectly,developers manipulate the object model,which represents the database

    • For this,Windows application must be created

    • Add new LINQ to SQL class items to the project

    • Drag and drop tables and make changes .It will be saved only in the object model

    • To save changes in the database use the following syntax

    • Database.Submitchanges();


    Database mapping
    Database mapping evolution of data access. It is a programming model that brings a much needed uniformity to accessing data from files, XML, database, registry, event log

    • 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

    • Utilise tables, views or stored procedures


    Modifying objects
    Modifying objects evolution of data access. It is a programming model that brings a much needed uniformity to accessing data from files, XML, database, registry, event log

    • UpdateSet object properties

    • Deletecontext.Table.DeleteOnSubmit(object)

    • Insertcontext.Table.InsertOnSubmit(object)

    • Commit changes backcontext.SubmitChanges()Transactional - all or nothing


    Linq is beneficial than stored procedures
    LINQ evolution of data access. It is a programming model that brings a much needed uniformity to accessing data from files, XML, database, registry, event logis beneficial than Stored Procedures

    • Debugging(Complex dedug in SP)

    • Deployment(.dll)

    • Type Safety (Errors)


    Linq and extension methods
    LINQ and Extension Methods evolution of data access. It is a programming model that brings a much needed uniformity to accessing data from files, XML, database, registry, event log

    • Extend functionality to an existing class without needing to subclass it

    • To add extension methods to objects implementing the Ienumerable interface,you need a reference to system.core.dll


    Linq to xml
    LINQ TO XML evolution of data access. It is a programming model that brings a much needed uniformity to accessing data from files, XML, database, registry, event log

    Earlier Xpath or Xquery were used to manipulate XML documents, at present LINQ to XML concepts are used

    Add a reference to the System.xml.linq.dll in the project and also import System.xml.linqnamespace

    Tree

    -> Xdocument

    ->XElement

    ->XAttribute

    LOAD

    XDocumentLibraryBooks = new Xdocument();

    LibraryBooks = Xdocument.load(“Books.xml”);


    Future developments
    Future developments evolution of data access. It is a programming model that brings a much needed uniformity to accessing data from files, XML, database, registry, event log

    • BlinqScaffold web UI for list/view/update pages

    • PLINQParallel query processing over many CPUs

    • SyncLINQ & Continuous LINQUpdated results via INotifyCollectionChanged


    • PLINQ evolution of data access. It is a programming model that brings a much needed uniformity to accessing data from files, XML, database, registry, event log

    • Microsoft, as a part of the Parallel Extensions, is developing PLINQ, or Parallel LINQ, a parallel execution engine for LINQ queries. It defines the IParallelEnumerable<T> interface. If the source collection implements this interface, the parallel execution engine is invoked. The PLINQ engine executes a query in a distributed manner on a multi-core or multi-processor system.[28]


    Net features used
    .NET features used evolution of data access. It is a programming model that brings a much needed uniformity to accessing data from files, XML, database, registry, event log

    .NET Framework 3.5

    • Anonymous types (shaping)

    • Extension methods (query operators)

    • Type inference (var keyword)

    • Lambda expressions (query syntax)


    ad