Skip to content

Latest commit

 

History

History
36 lines (24 loc) · 2.03 KB

how-to-execute-a-polymorphic-query.md

File metadata and controls

36 lines (24 loc) · 2.03 KB
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
csharp
vb
2f05da1e-845b-4f14-83e4-c6353a850553

How to: Execute a Polymorphic Query

This topic shows how to execute a polymorphic Entity SQL query using the OFTYPE operator.

To run the code in this example

  1. 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.

  2. 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)]

  3. Modify the conceptual model to have a table-per-hierarchy inheritance by following the steps in Walkthrough: Mapping Inheritance - Table-per-Hierarchy.

Example

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)]

See also