Method-Based Query Syntax Examples: Conversion

 

The examples in this topic demonstrate how to use the ToArray<TSource>, ToDictionary and ToList<TSource> methods to query the AdventureWorks Sales Model using method-based query syntax. The AdventureWorks Sales Model used in these examples is built from the Contact, Address, Product, SalesOrderHeader, and SalesOrderDetail tables in the AdventureWorks sample database.

The examples in this topic use the following using/Imports statements:

[!CODE [DP L2E Examples#ImportsUsing](../CodeSnippet/VS_Snippets_Data/DP L2E Examples#importsusing)]

Example

The following example uses the ToArray<TSource> method to immediately evaluate a sequence into an array.

[!CODE [DP L2E Examples#ToArray](../CodeSnippet/VS_Snippets_Data/DP L2E Examples#toarray)]

Example

The following example uses the ToDictionary method to immediately evaluate a sequence and a related key expression into a dictionary.

[!CODE [DP L2E Examples#ToDictionary](../CodeSnippet/VS_Snippets_Data/DP L2E Examples#todictionary)]

Example

The following example uses the ToList<TSource> method to immediately evaluate a sequence into a List<T>, where T is of type DataRow.

[!CODE [DP L2E Examples#ToList](../CodeSnippet/VS_Snippets_Data/DP L2E Examples#tolist)]

Queries in LINQ to Entities

Show: