Wednesday, June 11, 2014

What is LINQ (Language-Integrated Query)?

Language-Integrated Query (LINQ) is a set of features introduced in Visual Studio 2008 that extends powerful query capabilities to the language syntax of C# and Visual Basic. LINQ introduces standard, easily-learned patterns for querying and updating data, and the technology can be extended to support potentially any kind of data store. Visual Studio includes LINQ provider assemblies that enable the use of LINQ with .NET Framework collections, SQL Server databases, ADO.NET Datasets, and XML documents.

Simple example on LINQ:

All LINQ query operations consist of three distinct actions:

1.Obtain the data source.
2.Create the query.
3.Execute the query.

    Public Class Customer
        Public Property Name As String
        Public Property City As String
    End Class
        'The Three Parts of a LINQ Query '

        '1. Data source '
        Dim customers As New List(Of Customer)

        Dim objCustomer As New Customer
        objCustomer.Name = "Miller"
        objCustomer.City = "Camp Hill"
        customers.Add(objCustomer)

        objCustomer = New Customer
        objCustomer.Name = "John"
        objCustomer.City = "Harrisburg"
        customers.Add(objCustomer)

        objCustomer = New Customer
        objCustomer.Name = "Wayne"
        objCustomer.City = "Enola"
        customers.Add(objCustomer)

        objCustomer = New Customer
        objCustomer.Name = "Julie"
        objCustomer.City = "Enola"
        customers.Add(objCustomer)

        '2. Query creation '
        Dim enolaCustomers = From oCustomer As Customer In customers _
                               Where oCustomer.City = "Enola" _
                               Select oCustomer


        '3. Query Execution '
        For Each oCustomer As Customer In enolaCustomers
            Response.Write(oCustomer.Name + "<br/>")
        Next
        'Result will be :'
        Wayne
        Julie

No comments:

Post a Comment

React-select is very slow on larger list - Found solution - using react-window

 I had more than 4000 items in searchable dropdownlist. I have used react-select but it was very slow. finally I found complete solution to ...