다음을 통해 공유


방법: 계층당 하나의 테이블 상속을 사용하여 모델 정의(Entity Framework)

EDM(엔터티 데이터 모델)에서는 여러 방법으로 상속을 구현할 수 있습니다. 계층당 하나의 테이블 방법에서는 저장소에 있는 한 테이블을 사용하여 상속 계층 구조에 있는 모든 형식의 데이터를 관리합니다. 이 단원에는 계층당 하나의 테이블 시나리오에서 구현된 간단한 상속 계층 구조에 대한 스키마와 매핑이 포함되어 있습니다.

EDM에서 계층당 하나의 테이블 모델을 기반으로 하는 상속 계층 구조의 개념 스키마는 파생 형식 선언에 BaseType 특성 할당을 포함합니다. 이 시나리오에서는 저장소 모델에서 하나의 테이블만 사용하여 데이터를 관리하더라도 각 EntityType이 개별적으로 선언됩니다. EntityContainer 선언에는 기본 형식에 대한 EntitySet 선언만 포함됩니다.

이 예제에서 연결은 연결 정의가 EntitySet 선언을 참조하므로 기본 형식에 대해 구현됩니다. 파생 형식은 EntityContainerEntitySet 선언이 없습니다.

계층당 하나의 테이블 상속 계층 구조에 대한 개념 스키마를 구현하려면

  1. 클래스 라이브러리 프로젝트를 만들고 새 ADO.NET 엔터티 데이터 모델 빈 모델을 추가합니다.

  2. XML 편집기를 사용하여 .edmx 파일을 엽니다.

  3. Person 엔터티 기본 형식을 선언한 다음 기본 형식에서 Student, InstructorAdministrator 엔터티를 파생시켜 CSDL(개념 스키마 정의 언어) 스키마를 구현합니다.

  4. 아래에 표시된 구문을 사용합니다. Student, Instructor 및 Administrator 형식은 Person 기본 형식의 속성을 상속합니다. Student 형식은 EnrollmentDate 속성을 추가합니다. InstructorHireDate 속성을 추가합니다.

  5. AdminDateAdministrator 엔터티에 추가하여 부서의 관리자가 된 날짜를 나타냅니다.

  6. Person 기본 형식과 People이라는 EntitySet에 논리적으로 포함된 파생 형식인 StudentInstructor를 구현합니다.

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

계층당 하나의 테이블 상속 계층 구조에 대한 저장소 메타데이터를 구현하려면

  1. 계층 구조에 있는 Student, InstructorAdministrator 형식에 사용할 테이블 한 개를 저장소에서 구현합니다.

  2. Person 기본 형식에서 파생되는 세 형식을 선언합니다. Person 테이블만 있으면 모든 파생 형식의 데이터를 포함할 수 있습니다. 마지막 속성인 PersonCategory는 판별자 열입니다. 이 속성 값은 이러한 파생된 형식의 인스턴스가 Student, Instructor 또는 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>

SQL Server Management Studio를 사용하여 데이터베이스를 생성하려면

  1. SQL Server Management Studio에서 다음 스크립트를 사용하여 이 예제와 방법: 형식당 하나의 테이블 상속을 사용하여 모델 정의(Entity Framework) 예제에서 사용되는 데이터베이스를 생성합니다.

  2. 파일 메뉴에서 새로 만들기를 가리킨 다음 데이터베이스 엔진 쿼리를 클릭하여 SQL Server Management Studio에서 SchoolData 데이터베이스 및 스키마를 만듭니다.

  3. 데이터베이스 엔진에 연결 대화 상자에 localhost 또는 다른 SQL Server 인스턴스의 이름을 입력한 다음 연결을 클릭합니다.

  4. 다음 Transact-SQL 스크립트를 쿼리 창에 붙여넣은 후 실행을 클릭합니다.

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]

계층당 하나의 테이블 상속 계층 구조에 대한 매핑 사양을 구현하려면

  1. 계층당 하나의 테이블 개념 스키마의 엔터티를 저장소 스키마의 엔터티에 매핑합니다. 그러면 하나의 테이블에 이 계층당 하나의 테이블 예제에서 정의한 세 형식의 데이터가 포함됩니다. 매핑 스키마는 MSL(매핑 사양 언어)로 작성합니다.

  2. 이 계층당 하나의 테이블 상속 예제에서 판별자 열을 사용하여 계층 구조의 형식을 지정합니다. 이 스키마의 Condition 줄에는 ColumnValue 특성이 있습니다. Value0PersonCategoryColumn은 기본 형식 Person을 나타냅니다. Value1Student 형식을 나타내고, Value2Instructor 형식을 나타내며, Value 3은 Administrator 형식을 나타냅니다.

  3. People이라는 단일 EntitySetMapping에서 계층 구조의 세 EntityTypeMapping 세그먼트를 모두 매핑합니다. 다음은 전체 매핑 사양입니다.

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

참고 항목

작업

방법: 계층당 하나의 테이블 상속을 사용하여 개체 쿼리 만들기 및 실행(Entity Framework)
방법: 계층당 하나의 테이블 상속을 사용하여 개체 추가 및 수정(Entity Framework)
방법: 계층당 하나의 테이블 상속을 사용하여 개체 쿼리 만들기 및 실행(Entity Framework)

개념

상속(EDM)