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