How to: Execute a Query that Returns a Data Type
This article is relevant to entity models that utilize the deprecated Visual Studio integration of Telerik Data Access. The current documentation of the Data Access framework is available here.
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.
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);
}
}
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