Share via


Cómo definir un modelo con herencia de tabla por jerarquía (Entity Framework)

La herencia se puede implementar de varias formas en el Entity Data Model (EDM). El método de tabla por jerarquía (TPH, Table Per Hierarchy) emplea una tabla del almacenamiento para mantener los datos de todos los tipos en una jerarquía de la herencia. En esta sección se incluyen los esquemas y la asignación de una jerarquía de herencia simple implementada en el escenario con una tabla por jerarquía.

En el EDM, el esquema conceptual para la jerarquía de la herencia en el modelo de tabla por jerarquía incluye la asignación del atributo BaseType en las declaraciones de los tipos derivados. Cada EntityType se declara por separado aunque el modelo de almacenamiento use únicamente una tabla para administrar los datos en este escenario. La declaración del EntityContainer sólo incluye la declaración del EntitySet correspondiente al tipo base.

Las asociaciones de este ejemplo se implementan con el tipo base debido a que sus definiciones se refieren a declaraciones de EntitySet. Un tipo derivado no tiene una declaración de EntitySet en EntityContainer.

Para implementar el esquema conceptual de la jerarquía de herencia de tabla por jerarquía

  1. Cree un proyecto de una biblioteca de clases y agregue un nuevo modelo vacío de ADO.NET Entity Data Model.

  2. Abra el archivo .edmx con un editor XML.

  3. Implemente el esquema del lenguaje de definición de esquemas conceptuales (CSDL, Conceptual Schema Definition Language) declarando el tipo base de la entidad Person y derivando las entidades Student, Instructor y Administrator del tipo base.

  4. Utilice la sintaxis que se muestra a continuación. Los tipos Student, Instructor y Administrator heredan las propiedades del tipo base Person. El tipo Student agrega la propiedad EnrollmentDate. Instructor agrega la propiedad HireDate.

  5. Agregue AdminDate a la entidad Administrator para indicar la fecha en que esta persona se convirtió en administrador de un departamento.

  6. Implemente el tipo base Person y los tipos derivados Student y Instructor contenidos lógicamente en el EntitySet denominado People.

    <!-- CSDL content -->
    <edmx:ConceptualModels>
      <Schema xmlns="https://schemas.microsoft.com/ado/2006/04/edm" 
              Namespace="SchoolDataLib" Alias="Self">
        <EntityContainer Name="SchoolDataLibContainer">
          <EntitySet Name="Departments" 
                     EntityType="SchoolDataLib.Department" />
          <EntitySet Name="People" 
                     EntityType="SchoolDataLib.Person" />

          <AssociationSet Name="FK_Department_Administrator"
               Association="SchoolDataLib.FK_Department_Administrator">
            <End Role="Person" EntitySet="People" />
            <End Role="Department" EntitySet="Departments" />
          </AssociationSet>

        </EntityContainer>
        <EntityType Name="Department">
          <!--Base type table-per-type inheritance-->
          <Key>
            <PropertyRef Name="DepartmentID" />
          </Key>
          <Property Name="DepartmentID" Type="Int32" Nullable="false" />
          <Property Name="Name" Type="String" Nullable="false" />
          <Property Name="Budget" Type="Decimal" Nullable="false" />
          <Property Name="StartDate" Type="DateTime" Nullable="false" />
          <NavigationProperty Name="Administrator"
                 Relationship="SchoolDataLib.FK_Department_Administrator"
                 FromRole="Department" ToRole="Person" />
        </EntityType>

        <EntityType Name="DeptBusiness"
                    BaseType="SchoolDataLib.Department">
          <Property Name="LegalBudget" 
                    Type="Decimal" Nullable="false" />
          <Property Name="AccountingBudget" 
                    Type="Decimal" Nullable="false" />
        </EntityType>

        <EntityType Name="DeptEngineering" 
                    BaseType="SchoolDataLib.Department">
          <Property Name="FiberOpticsBudget" 
                    Type="Decimal" Nullable="false" />
          <Property Name="LabBudget" 
                    Type="Decimal" Nullable="false" />
        </EntityType>

        <EntityType Name="DeptMusic" 
                    BaseType="SchoolDataLib.Department">
          <Property Name="TheaterBudget" 
                    Type="Decimal" Nullable="false" />
          <Property Name="InstrumentBudget" 
                    Type="Decimal" Nullable="false" />
        </EntityType>

        <Association Name="FK_Department_Administrator">
          <End Role="Person" 
               Type="SchoolDataLib.Person" Multiplicity="0..1" />
          <End Role="Department" 
               Type="SchoolDataLib.Department" Multiplicity="*" />
        </Association>

        <EntityType Name="Person">
          <!--Base type table-per-hierarchy inheritance-->
          <Key>
            <PropertyRef Name="PersonID" />
          </Key>
          <Property Name="PersonID" Type="Int32" Nullable="false" />
          <Property Name="FirstName" Type="String" Nullable="false" />
          <Property Name="LastName" Type="String" Nullable="false" />
          <NavigationProperty Name="Department"
                 Relationship="SchoolDataLib.FK_Department_Administrator"
                 FromRole="Person" ToRole="Department" />
        </EntityType>

        <EntityType Name="Student" BaseType="SchoolDataLib.Person">
          <Property Name="EnrollmentDate" Type="DateTime" />
        </EntityType>

        <EntityType Name="Instructor" BaseType="SchoolDataLib.Person">
          <Property Name="HireDate" Type="DateTime" />
        </EntityType>

        <EntityType Name="Administrator" BaseType="SchoolDataLib.Person">
          <Property Name="AdminDate" Type="DateTime" />
        </EntityType>

      </Schema>
    </edmx:ConceptualModels>

Para implementar los metadatos de almacenamiento de la jerarquía de herencia de tabla por jerarquía

  1. Implemente una tabla en el almacenamiento de los tipos Student, Instructor y Administrator de la jerarquía.

  2. Declare los tres tipos derivados del tipo base Person. La única tabla que debe contener los datos de todos los tipos derivados es la tabla Person. La propiedad final, PersonCategory, es la columna discriminadora. Su valor se usa para especificar si una instancia derivada de uno de estos tipos es un Student, Instructor o Administrator.

    <!-- SSDL content -->
    <edmx:StorageModels>
      <Schema xmlns="https://schemas.microsoft.com/ado/2006/04/edm/ssdl" 
              Namespace="SchoolDataLib.Target" 
              Alias="Self" Provider="System.Data.SqlClient" 
              ProviderManifestToken="2005">
        <EntityContainer Name="dbo">
          <EntitySet Name="Department" 
                     EntityType="SchoolDataLib.Target.Department" />
          <EntitySet Name="DeptBusiness" 
                     EntityType="SchoolDataLib.Target.DeptBusiness" />
          <EntitySet Name="DeptEngineering" 
                     EntityType="SchoolDataLib.Target.DeptEngineering" />
          <EntitySet Name="DeptMusic" 
                     EntityType="SchoolDataLib.Target.DeptMusic" />
          <EntitySet Name="Person" 
                     EntityType="SchoolDataLib.Target.Person" />

          <AssociationSet Name="FK_Department_Administrator"
              Association="SchoolDataLib.Target.FK_Department_Administrator">
            <End Role="Person" EntitySet="Person" />
            <End Role="Department" EntitySet="Department" />
          </AssociationSet>
        </EntityContainer>
        <EntityType Name="Department">
          <Key>
            <PropertyRef Name="DepartmentID" />
          </Key>
          <Property Name="DepartmentID" Type="int" Nullable="false" />
          <Property Name="Name" Type="nvarchar" 
                    Nullable="false" MaxLength="50" />
          <Property Name="Budget" Type="money" Nullable="false" />
          <Property Name="StartDate" Type="datetime" Nullable="false"/>
          <Property Name="Administrator" Type="int" />
        </EntityType>

        <EntityType Name="DeptBusiness">
          <Key>
            <PropertyRef Name="BusinessDeptID" />
          </Key>
          <Property Name="BusinessDeptID" 
                    Type="int" Nullable="false" />
          <Property Name="LegalBudget" 
                    Type="money" Nullable="false" />
          <Property Name="AccountingBudget" 
                    Type="money" Nullable="false" />
        </EntityType>

        <EntityType Name="DeptEngineering">
          <Key>
            <PropertyRef Name="EngineeringDeptID" />
          </Key>
          <Property Name="EngineeringDeptID" 
                    Type="int" Nullable="false" />
          <Property Name="FiberOpticsBudget" 
                    Type="money" Nullable="false" />
          <Property Name="LabBudget" 
                    Type="money" Nullable="false" />
        </EntityType>

        <EntityType Name="DeptMusic">
          <Key>
            <PropertyRef Name="DeptMusicID" />
          </Key>
          <Property Name="DeptMusicID" 
                    Type="int" Nullable="false" />
          <Property Name="TheaterBudget" 
                    Type="money" Nullable="false" />
          <Property Name="InstrumentBudget" 
                    Type="money" Nullable="false" />
        </EntityType>

        <EntityType Name="Person">
          <Key>
            <PropertyRef Name="PersonID" />
          </Key>
          <Property Name="PersonID"
                    Type="int" Nullable="false" />
          <Property Name="FirstName" 
                    Type="nvarchar" Nullable="false" MaxLength="50" />
          <Property Name="LastName" 
                    Type="nvarchar" Nullable="false" MaxLength="50" />
          <Property Name="HireDate" Type="datetime" />
          <Property Name="EnrollmentDate" Type="datetime" />
          <Property Name="AdminDate" Type="datetime" />
          <Property Name="PersonCategory" 
                    Type="smallint" Nullable="false" />
        </EntityType>

        <Association Name="FK_Department_Administrator">
          <End Role="Person" 
             Type="SchoolDataLib.Target.Person" Multiplicity="0..1"/>
          <End Role="Department" 
             Type="SchoolDataLib.Target.Department" Multiplicity="*"/>
          <ReferentialConstraint>
            <Principal Role="Person">
              <PropertyRef Name="PersonID" />
            </Principal>
            <Dependent Role="Department">
              <PropertyRef Name="Administrator" />
            </Dependent>
          </ReferentialConstraint>
        </Association>
      </Schema>
    </edmx:StorageModels>

Para generar la base de datos mediante SQL Server Management Studio

  1. Use el siguiente script en SQL Server Management Studio para generar la base de datos que se usa en este ejemplo y en el ejemplo Cómo definir un modelo con herencia de tabla por tipo (Entity Framework).

  2. Seleccione Nuevo en el menú Archivo y haga clic en Consulta de motor de base de datos para crear la base de datos SchoolData y el esquema con SQL Server Management Studio.

  3. Escriba el host local o el nombre de otra instancia de SQL Server en el cuadro de diálogo Conectarse al motor de base de datos y haga clic en Conectar.

  4. Pegue el siguiente script de Transact-SQL en la ventana de consulta y, a continuación, haga clic en Ejecutar.

USE [master]
GO

CREATE DATABASE [SchoolData] 
GO

USE [SchoolData]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[DeptBusiness]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[DeptBusiness](
    [BusinessDeptID] [int] NOT NULL,
    [LegalBudget] [money] NOT NULL,
    [AccountingBudget] [money] NOT NULL,
 CONSTRAINT [PK_DeptBusiness] PRIMARY KEY CLUSTERED 
(
    [BusinessDeptID] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[DeptEngineering]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[DeptEngineering](
    [EngineeringDeptID] [int] NOT NULL,
    [FiberOpticsBudget] [money] NOT NULL,
    [LabBudget] [money] NOT NULL,
 CONSTRAINT [PK_DeptEngineering] PRIMARY KEY CLUSTERED 
(
    [EngineeringDeptID] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[DeptMusic]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[DeptMusic](
    [DeptMusicID] [int] NOT NULL,
    [TheaterBudget] [money] NOT NULL,
    [InstrumentBudget] [money] NOT NULL,
 CONSTRAINT [PK_DeptMusic] PRIMARY KEY CLUSTERED 
(
    [DeptMusicID] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Course]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Course](
    [CourseID] [int] NOT NULL,
    [Title] [nvarchar](100) NOT NULL,
    [StartDate] [datetime] NOT NULL,
    [EndDate] [datetime] NOT NULL,
    [Credits] [int] NULL,
 CONSTRAINT [PK_Course] PRIMARY KEY CLUSTERED 
(
    [CourseID] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Person]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Person](
    [PersonID] [int] NOT NULL,
    [FirstName] [nvarchar](50) NOT NULL,
    [LastName] [nvarchar](50) NOT NULL,
    [HireDate] [datetime] NULL,
    [EnrollmentDate] [datetime] NULL,
    [PersonCategory] [smallint] NOT NULL,
    [AdminDate] [datetime] NULL,
 CONSTRAINT [PK_Person] PRIMARY KEY CLUSTERED 
(
    [PersonID] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Enrollment]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Enrollment](
    [EnrollmentID] [int] NOT NULL,
    [CourseID] [int] NOT NULL,
    [StudentID] [int] NOT NULL,
 CONSTRAINT [PK_Enrollment] PRIMARY KEY CLUSTERED 
(
    [EnrollmentID] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[CourseInstructor]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[CourseInstructor](
    [CourseInstructorID] [int] NOT NULL,
    [CourseID] [int] NOT NULL,
    [InstructorID] [int] NOT NULL,
 CONSTRAINT [PK_CourseInstructor] PRIMARY KEY CLUSTERED 
(
    [CourseInstructorID] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Department]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Department](
    [DepartmentID] [int] NOT NULL,
    [Name] [nvarchar](50) NOT NULL,
    [Budget] [money] NOT NULL,
    [StartDate] [datetime] NOT NULL,
    [Administrator] [int] NULL,
 CONSTRAINT [PK_Department] PRIMARY KEY CLUSTERED 
(
    [DepartmentID] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Enrollment_Course]') AND parent_object_id = OBJECT_ID(N'[dbo].[Enrollment]'))
ALTER TABLE [dbo].[Enrollment]  WITH CHECK ADD  CONSTRAINT [FK_Enrollment_Course] FOREIGN KEY([CourseID])
REFERENCES [dbo].[Course] ([CourseID])
GO
ALTER TABLE [dbo].[Enrollment] CHECK CONSTRAINT [FK_Enrollment_Course]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Enrollment_Student]') AND parent_object_id = OBJECT_ID(N'[dbo].[Enrollment]'))
ALTER TABLE [dbo].[Enrollment]  WITH CHECK ADD  CONSTRAINT [FK_Enrollment_Student] FOREIGN KEY([StudentID])
REFERENCES [dbo].[Person] ([PersonID])
GO
ALTER TABLE [dbo].[Enrollment] CHECK CONSTRAINT [FK_Enrollment_Student]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_CourseInstructor_Course]') AND parent_object_id = OBJECT_ID(N'[dbo].[CourseInstructor]'))
ALTER TABLE [dbo].[CourseInstructor]  WITH CHECK ADD  CONSTRAINT [FK_CourseInstructor_Course] FOREIGN KEY([CourseID])
REFERENCES [dbo].[Course] ([CourseID])
GO
ALTER TABLE [dbo].[CourseInstructor] CHECK CONSTRAINT [FK_CourseInstructor_Course]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_CourseInstructor_Instructor]') AND parent_object_id = OBJECT_ID(N'[dbo].[CourseInstructor]'))
ALTER TABLE [dbo].[CourseInstructor]  WITH CHECK ADD  CONSTRAINT [FK_CourseInstructor_Instructor] FOREIGN KEY([InstructorID])
REFERENCES [dbo].[Person] ([PersonID])
GO
ALTER TABLE [dbo].[CourseInstructor] CHECK CONSTRAINT [FK_CourseInstructor_Instructor]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Department_Administrator]') AND parent_object_id = OBJECT_ID(N'[dbo].[Department]'))
ALTER TABLE [dbo].[Department]  WITH CHECK ADD  CONSTRAINT [FK_Department_Administrator] FOREIGN KEY([Administrator])
REFERENCES [dbo].[Person] ([PersonID])
GO
ALTER TABLE [dbo].[Department] CHECK CONSTRAINT [FK_Department_Administrator]

Para implementar la especificación de asignación de la jerarquía de herencia de tabla por jerarquía

  1. Asigne las entidades del esquema conceptual con una tabla por jerarquía a las entidades del esquema de almacenamiento. Se usa una sola tabla para contener los datos de los tres tipos definidos en este ejemplo de herencia de tabla por jerarquía. El esquema de asignación se escribe en el lenguaje de especificación de asignaciones (MSL, Mapping Specification Language).

  2. Use una columna discriminadora para especificar el tipo en la jerarquía de este ejemplo de herencia de una tabla por jerarquía. La línea Condition de este esquema incluye los atributos Column y Value. La PersonCategoryColumn con un Value de 0 indica el tipo base Person. El Value1 indica el tipo Student; el Value2 indica el tipo Instructor; y el Value 3 indica el tipo Administrator.

  3. Asigne los tres segmentos EntityTypeMapping de la jerarquía bajo una única EntitySetMapping denominada People. A continuación se muestra la especificación completa de la asignación.

    <!-- C-S mapping content -->
    <edmx:Mappings>
      <Mapping xmlns="urn:schemas-microsoft-com:windows:storage:mapping:CS"
               Space="C-S">
        <Alias Key="Model" Value="SchoolDataLib" />
        <Alias Key="Target" Value="SchoolDataLib.Target" />
        <EntityContainerMapping CdmEntityContainer="SchoolDataLibContainer" 
                  StorageEntityContainer="dbo">
          
          <!-- Mapping for table-per-type inheritance-->
          <EntitySetMapping Name="Departments">
            <EntityTypeMapping 
                     TypeName="IsTypeOf(SchoolDataLib.Department)">
              <MappingFragment StoreEntitySet="Department">
                <ScalarProperty 
                     Name="DepartmentID" ColumnName="DepartmentID" />
                <ScalarProperty Name="Name" ColumnName="Name" />
                <ScalarProperty Name="Budget" ColumnName="Budget" />
                <ScalarProperty 
                     Name="StartDate" ColumnName="StartDate" />
              </MappingFragment>
            </EntityTypeMapping>

            <EntityTypeMapping TypeName="SchoolDataLib.DeptBusiness">
              <MappingFragment StoreEntitySet="DeptBusiness">
                <ScalarProperty Name="DepartmentID" 
                                ColumnName="BusinessDeptID" />
                <ScalarProperty Name="AccountingBudget" 
                                ColumnName="AccountingBudget" />
                <ScalarProperty Name="LegalBudget" 
                                ColumnName="LegalBudget" />
              </MappingFragment>
            </EntityTypeMapping>

            <EntityTypeMapping TypeName="SchoolDataLib.DeptEngineering">
              <MappingFragment StoreEntitySet="DeptEngineering">
                <ScalarProperty Name="DepartmentID" 
                                ColumnName="EngineeringDeptID" />
                <ScalarProperty Name="FiberOpticsBudget" 
                                ColumnName="FiberOpticsBudget" />
                <ScalarProperty Name="LabBudget" 
                                ColumnName="LabBudget" />
              </MappingFragment>
            </EntityTypeMapping>

            <EntityTypeMapping TypeName="SchoolDataLib.DeptMusic">
              <MappingFragment StoreEntitySet="DeptMusic">
                <ScalarProperty Name="DepartmentID" 
                                ColumnName="DeptMusicID" />
                <ScalarProperty Name="TheaterBudget" 
                                ColumnName="TheaterBudget" />
                <ScalarProperty Name="InstrumentBudget" 
                                ColumnName="InstrumentBudget" />
              </MappingFragment>
            </EntityTypeMapping>
          </EntitySetMapping>

          <!--Mapping for table-per-hierarchy inheritance-->
          <EntitySetMapping Name="People">
            <EntityTypeMapping TypeName="SchoolDataLib.Person">
              <MappingFragment StoreEntitySet="Person">
                <ScalarProperty Name="PersonID" ColumnName="PersonID"/>
                <ScalarProperty Name="FirstName" ColumnName="FirstName"/>
                <ScalarProperty Name="LastName" ColumnName="LastName"/>
                <Condition ColumnName="PersonCategory" Value="0" />
              </MappingFragment>
            </EntityTypeMapping>

            <EntityTypeMapping TypeName="SchoolDataLib.Student">
              <MappingFragment StoreEntitySet="Person">
                <ScalarProperty Name="PersonID" ColumnName="PersonID" />
                <ScalarProperty Name="FirstName" ColumnName="FirstName" />
                <ScalarProperty Name="LastName" ColumnName="LastName" />
                <ScalarProperty 
                  Name="EnrollmentDate" ColumnName="EnrollmentDate" />
                <Condition ColumnName="PersonCategory" Value="1" />
              </MappingFragment>
            </EntityTypeMapping>

            <EntityTypeMapping TypeName="SchoolDataLib.Instructor">
              <MappingFragment StoreEntitySet="Person">
                <ScalarProperty Name="PersonID" ColumnName="PersonID" />
                <ScalarProperty Name="FirstName" ColumnName="FirstName" />
                <ScalarProperty Name="LastName" ColumnName="LastName" />
                <ScalarProperty Name="HireDate" ColumnName="HireDate" />
                <Condition ColumnName="PersonCategory" Value="2" />
              </MappingFragment>
            </EntityTypeMapping>

            <EntityTypeMapping TypeName="SchoolDataLib.Administrator">
              <MappingFragment StoreEntitySet="Person">
                <ScalarProperty Name="PersonID" ColumnName="PersonID" />
                <ScalarProperty Name="FirstName" ColumnName="FirstName" />
                <ScalarProperty Name="LastName" ColumnName="LastName" />
                <ScalarProperty Name="AdminDate" ColumnName="AdminDate" />
                <Condition ColumnName="PersonCategory" Value="3" />
              </MappingFragment>
            </EntityTypeMapping>

          </EntitySetMapping>


          <AssociationSetMapping Name="FK_Department_Administrator"
                    TypeName="SchoolDataLib.FK_Department_Administrator"
                    StoreEntitySet="Department">
            <EndProperty Name="Person">
              <ScalarProperty Name="PersonID" ColumnName="Administrator" />
            </EndProperty>
            <EndProperty Name="Department">
              <ScalarProperty Name="DepartmentID" ColumnName="DepartmentID" />
            </EndProperty>
            <Condition ColumnName="Administrator" IsNull="false" />
          </AssociationSetMapping>
        </EntityContainerMapping>
      </Mapping>
    </edmx:Mappings>

Vea también

Tareas

Cómo crear y ejecutar consultas de objeto con herencia de tabla por jerarquía (Entity Framework)
Cómo agregar y modificar objetos con herencia de tabla por jerarquía (Entity Framework)
Cómo crear y ejecutar consultas de objeto con herencia de tabla por jerarquía (Entity Framework)

Conceptos

Herencia (EDM)