Condividi tramite


Procedura: definire un modello con ereditarietà tabella per gerarchia (Entity Framework)

L'ereditarietà può essere implementata in diversi modi in Entity Data Model (EDM). Il metodo tabella per gerarchia utilizza una tabella nell'archivio per gestire i dati per tutti i tipi in una gerarchia di ereditarietà. In questa sezione sono inclusi gli schemi e il mapping per una gerarchia di ereditarietà semplice implementata nello scenario tabella per gerarchia.

Nel modello EDM lo schema concettuale per una gerarchia di ereditarietà nel modello tabella per gerarchia include l'assegnazione di attributi BaseType nelle dichiarazioni dei tipi derivati. Ogni oggetto EntityType viene dichiarato separatamente anche se il modello di archiviazione utilizza una sola tabella per gestire i dati per questo scenario. La dichiarazione di EntityContainer include solo la dichiarazione di EntitySet per il tipo di base.

Le associazioni in questo esempio vengono implementate nel tipo di base, in quanto le definizioni delle associazioni fanno riferimento a dichiarazioni di EntitySet. Un tipo derivato non include alcuna dichiarazione di EntitySet in EntityContainer.

Per implementare lo schema concettuale per la gerarchia di ereditarietà tabella per gerarchia

  1. Creare un progetto Libreria di classi e aggiungere un nuovo modello ADO.NET Entity Data Model vuoto.

  2. Aprire il file con estensione edmx utilizzando un editor XML.

  3. Implementare lo schema CSDL (Conceptual Schema Definition Language) dichiarando il tipo di base dell'entità Person e derivando le entità Student, Instructor e Administrator dal tipo di base.

  4. Utilizzare la sintassi illustrata di seguito. I tipi Student, Instructor e Administrator ereditano le proprietà del tipo di base Person. Il tipo Student aggiunge la proprietà EnrollmentDate. Instructor aggiunge la proprietà HireDate.

  5. Aggiungere AdminDate all'entità Administrator per indicare la data in cui questa persona è diventata responsabile di un reparto.

  6. Implementare il tipo di base Person e i tipi derivati Student e Instructor contenuti logicamente dall'oggetto EntitySet denominato 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>

Per implementare i metadati di archiviazione per la gerarchia di ereditarietà tabella per gerarchia

  1. Implementare una tabella nell'archivio per i tipi Student, Instructor e Administrator nella gerarchia.

  2. Dichiarare i tre tipi derivati dal tipo di base Person. Per contenere dati per tutti i tipi derivati, è necessaria solo la tabella Person. La proprietà finale, PersonCategory, è la colonna discriminatore. Il suo valore viene utilizzato per specificare se un'istanza derivata di uno di questi tipi è un oggetto 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>

Per generare il database tramite SQL Server Management Studio

  1. Utilizzare lo script seguente in SQL Server Management Studio per generare il database incluso in questo esempio e nell'esempio Procedura: definire un modello con ereditarietà tabella per tipo (Entity Framework).

  2. Scegliere Nuovo dal menu File, quindi fare clic su Query del Motore di database per creare lo schema e il database SchoolData con SQL Server Management Studio.

  3. Nella finestra di dialogo Connetti al Motore di database digitare localhost o il nome di un'altra istanza di SQL Server, quindi fare clic su Connetti.

  4. Incollare lo script Transact-SQL seguente nella finestra di query, quindi fare clic su Esegui.

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]

Per implementare la specifica di mapping per la gerarchia di ereditarietà tabella per gerarchia

  1. Eseguire il mapping delle entità dello schema concettuale tabella per gerarchia alle entità nello schema di archiviazione. Per contenere dati per i tre tipi definiti in questo esempio di tabella per gerarchia, viene utilizzata una singola tabella. Lo schema di mapping è scritto nel linguaggio MSL (Mapping Specification Language).

  2. Utilizzare una colonna discriminatore per specificare il tipo nella gerarchia in questo esempio di ereditarietà tabella per gerarchia. La riga Condition di questo schema include gli attributi Column e Value. L'oggetto ColumnPersonCategory con Value uguale a 0 indica il tipo di base Person. Value uguale a 1 indica il tipo Student, Value uguale a 2 indica il tipo Instructor e Value uguale a 3 indica il tipo Administrator.

  3. Eseguire il mapping di tutti e tre i segmenti EntityTypeMapping nella gerarchia in un solo oggetto EntitySetMapping denominato People. Di seguito viene illustrata la specifica di mapping completa.

    <!-- 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>

Vedere anche

Attività

Procedura: creare ed eseguire query di oggetto utilizzando l'ereditarietà tabella per gerarchia (Entity Framework)
Procedura: aggiungere e modificare oggetti con ereditarietà tabella per gerarchia (Entity Framework)
Procedura: creare ed eseguire query di oggetto utilizzando l'ereditarietà tabella per gerarchia (Entity Framework)

Concetti

Ereditarietà (EDM)