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

How to: Execute a Query that Returns an Anonymous 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 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 Data Access Domain Model based on the Northwind database.

The following code is the LINQ example.

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 );
   }
}
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