How to: Execute a Query that Returns RefType Results


This topic shows how to execute a command against a conceptual model by using an EntityCommand object, and how to retrieve the RefType results by using an EntityDataReader.

To run the code in this example

  1. Add the AdventureWorks Sales Model to your project and configure your project to use the Entity Framework. For more information, see How to: Use the Entity Data Model Wizard.

  2. In the code page for your application, add the following using statements (Imports in Visual Basic):

    [!CODE [DP EntityServices Concepts#Namespaces](../CodeSnippet/VS_Snippets_Data/dp entityservices concepts#namespaces)]

This example executes a query that returns RefType results. If you pass the following query as an argument to the ExectueRefTypeQuery function, the function returns a reference to the entity:

[!CODE [DP EntityServices Concepts 2#REF2](../CodeSnippet/VS_Snippets_Data/dp entityservices concepts 2#ref2)]

If you pass a parameterized query, like the following, add the EntityParameter objects to the Parameters property on the EntityCommand object.

[!CODE [DP EntityServices Concepts 2#REF3](../CodeSnippet/VS_Snippets_Data/dp entityservices concepts 2#ref3)]

[!CODE [DP EntityServices Concepts#eSQLRefTypes](../CodeSnippet/VS_Snippets_Data/dp entityservices concepts#esqlreftypes)]

Entity SQL Reference
EntityClient Provider for the Entity Framework