description | title | ms.date | dev_langs | ms.assetid | ||
---|---|---|---|---|---|---|
Learn more about: How to: Execute a Polymorphic Query |
How to: Execute a Polymorphic Query |
03/30/2017 |
|
2f05da1e-845b-4f14-83e4-c6353a850553 |
This topic shows how to execute a polymorphic Entity SQL query using the OFTYPE operator.
-
Add the School 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.
-
In the code page for your application, add the following
using
directives (Imports
in Visual Basic):[!code-csharp[DP EntityServices Concepts#Namespaces](../../../../../samples/snippets/csharp/VS_Snippets_Data/dp entityservices concepts/cs/source.cs#namespaces)] [!code-vb[DP EntityServices Concepts#Namespaces](../../../../../samples/snippets/visualbasic/VS_Snippets_Data/dp entityservices concepts/vb/source.vb#namespaces)]
-
Modify the conceptual model to have a table-per-hierarchy inheritance by following the steps in Walkthrough: Mapping Inheritance - Table-per-Hierarchy.
The following example uses an OFTYPE operator to get and display a collection of only OnsiteCourses
from a collection of Courses
.
[!code-csharp[DP EntityServices Concepts#PolymorphicQuery](../../../../../samples/snippets/csharp/VS_Snippets_Data/dp entityservices concepts/cs/source.cs#polymorphicquery)] [!code-vb[DP EntityServices Concepts#PolymorphicQuery](../../../../../samples/snippets/visualbasic/VS_Snippets_Data/dp entityservices concepts/vb/source.vb#polymorphicquery)]