How to: Execute a Query that Returns a Data Type

This topic provides an example of how to execute a LINQ query that returns a collection of instances of a domain model type. It then iterates through the collection of Customers and displays the CustomerID for each Customer.

To run the code in this example, you need to create a new Telerik Data Access Domain Model based on the Northwind database.

The following code is the LINQ example.

C#


    using (EntitiesModel dbContext = new EntitiesModel())
    {
       IQueryable<Customer> customersQuery = from customer in dbContext.Customers
                                               select customer;
       Console.WriteLine("Customer IDs: ");
       foreach (var item in customersQuery)
       {
           Console.WriteLine(item.CustomerID);
       }
    }

VB.NET


    Using dbContext As New EntitiesModel()
     Dim customersQuery As IQueryable(Of Customer) = From customer In dbContext.Customers
                 Select customer
     Console.WriteLine("Customer IDs: ")
     For Each item In customersQuery
      Console.WriteLine(item.CustomerID)
     Next item
    End Using

See Also