Telerik OpenAccess ORM

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

Glossary Item Box

This topic provides examples of how to execute queries that return a collection of instances of an anonymous type such as: collection, row, and reference. The result of the query in these examples is a collection of row types.

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() )
{
   var query = from product
in dbContext.Products
               select
new
               {
                   
ProductId = product.ProductID,
                   ProductName = product.ProductName
               };
   
foreach ( var item in query )
   {
       Console.WriteLine(
"Product Id: {0} Product name: {1} ",
           item.ProductId, item.ProductName );
   }
}
VB.NET Copy Code
Using dbContext As New EntitiesModel()
 Dim query = From product In dbContext.Products
             Select New With {Key .ProductId = product.ProductID, Key .ProductName = product.ProductName}
 For Each item In query
  Console.WriteLine("Product Id: {0} Product name: {1} ", item.ProductId, item.ProductName)
 Next item
End Using

See Also