Telerik OpenAccess ORM

Telerik OpenAccess ORM Send comments on this topic.
How to: Execute a Query that Returns a Primitive Type
See Also
Programmer's Guide > Feature Reference > API > LINQ Guide > How to: Execute a Query that Returns a Primitive Type

Glossary Item Box

This topic provides examples of how to execute queries that return a primitive type.

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

The following code is the LINQ example.

C# Copy Code
using (EntitiesModel dbContext = new EntitiesModel())
{
   IQueryable<Int32> orderIdQuery = from order
in dbContext.Orders
                                       where order.CustomerID ==
"ALFKI" || order.CustomerID == null
                                       
select order.OrderID;

   
// Iterate through the collection of values.
   
foreach (Int32 id in orderIdQuery)
   {
       Console.WriteLine(
"{0}", id);
   }

   IQueryable<DateTime?> orderDateQuery = from order
in dbContext.Orders
                                           where order.CustomerID ==
"ALFKI" || order.CustomerID == null
                                           
select order.OrderDate;

   
// Iterate through the collection of values.
   
foreach (DateTime? orderDate in orderDateQuery)
   {
       
string orderDateMessage = "OrderDate not set";
       
if (orderDate != null)
       {
           orderDateMessage = orderDate.ToString();
       }
       Console.WriteLine(
"Ship Date: {0}.", orderDateMessage);
   }
}
VB.NET Copy Code
Using dbContext As New EntitiesModel()
 Dim orderIdQuery As IQueryable(Of Int32) = From order In dbContext.Orders
              Where order.CustomerID = "ALFKI" OrElse order.CustomerID Is Nothing
              Select order.OrderID
 ' Iterate through the collection of values.
 For Each id As Int32 In orderIdQuery
  Console.WriteLine("{0}", id)
 Next id
 Dim orderDateQuery As IQueryable(Of Date?) = From order In dbContext.Orders
                Where order.CustomerID = "ALFKI" OrElse order.CustomerID Is Nothing
                Select order.OrderDate
 ' Iterate through the collection of values.
 For Each orderDate? As Date In orderDateQuery
  Dim orderDateMessage As String = "OrderDate not set"
  If orderDate IsNot Nothing Then
   orderDateMessage = orderDate.ToString()
  End If
  Console.WriteLine("Ship Date: {0}.", orderDateMessage)
 Next orderDate
End Using

See Also