Data Access has been discontinued. Please refer to this page for more information.

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 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 a fluent model based on the Northwind database.

The following code is the LINQ example.

using (FluentModel dbContext = new FluentModel())
   IQueryable<Customer> customersQuery = from customer in dbContext.Customers
                                         select customer;
   Console.WriteLine("Customer IDs: ");
   foreach (var item in customersQuery)
Using dbContext As New FluentModel()
 Dim customersQuery As IQueryable(Of Customer) = From customer In dbContext.Customers
             Select customer
 Console.WriteLine("Customer IDs: ")
 For Each item In customersQuery
 Next item
End Using

See Also