次の方法で共有


Annotation Research Tool Schemas (EDM Sample Application)

The entities implemented in this application use the Entity Data Model (EDM) and are declared and defined in conceptual schema definition language (CSDL). Three entities are used to contain data on Web references, reference descriptors, and contacts. A fourth entity is necessary to contain pairs of identifiers connecting references and contacts. For more information about entities and associations, see EDM Specifications.

Each contact person can be associated with many references, and the association between contacts and references must be implemented as a many-to-many association. Each reference descriptor contains data on only one Web reference, but a reference can be related to many reference descriptors; the association between references and reference descriptors is implemented as many-to-one.

The following schema segment contains the declaration for the Reference entity. The Key property is specified as the ReferenceID property. There are three additional properties: DocumentType, DocumentText, and Locator. The Locator property contains the URL used to find the Web reference. Although DocumentType and DocumentText are not used by the application code in this example, they are provided for additional experimentation that uses the full text search features of SQL Server. For more information about schemas, see Schemas (EDM).

A navigation property named RefDescriptors provides a shortcut in application code to instances of the ReferenceDescriptor entity related to an instance of the Reference type. For more information about navigation properties, see Navigation Properties (EDM).

  <EntityType Name="Reference">
    <Key>
      <PropertyRef Name="ReferenceID" />
    </Key>
    <Property Name="ReferenceID" Type="Guid" Nullable="false" />
    <Property Name="DocumentType" Type="String" MaxLength="8" />
    <Property Name="DocumentText" Type="String" MaxLength="4000" />
    <Property Name="Locator" Type="String" Nullable="false"
         MaxLength="500" />
    <NavigationProperty Name="RefDescriptors"
         Relationship="Self.ReferenceDescriptor_Reference"
         FromRole="Reference" ToRole="ReferenceDescriptor" />
  </EntityType>

The ReferenceDescriptor entity is declared and defined in the following schema segment:

  <EntityType Name="ReferenceDescriptor">
    <Key>
      <PropertyRef Name="DescriptorID" />
    </Key>
    <Property Name="DescriptorID" Type="Guid" Nullable="false" />
    <Property Name="Annotation" Type="String" MaxLength="2000" />
    <Property Name="Keyword" Type="String" MaxLength="50" />
    <NavigationProperty Name="Reference"
          Relationship="Self.ReferenceDescriptor_Reference"
          FromRole="ReferenceDescriptor" ToRole="Reference" />
  </EntityType>

This entity contains an Annotation property and a Keyword property. One or both can be used to categorize and describe a Web page Reference. Either property can be Null, but one or the other should be assigned. The user interface in the application can validate if it is required.

A navigation property on the Reference entity uses the Association defined in the following schema segment:

  <Association Name="ReferenceDescriptor_Reference">
    <End Role="Reference" Type="ResearchCollaborationDataModel.Reference" Multiplicity="1" />
    <End Role="ReferenceDescriptor"
       Type="ResearchCollaborationDataModel.ReferenceDescriptor"
       Multiplicity="*" />
  </Association>

The <End> tags used in this association indicate Reference and ReferenceDescriptor entities in one-to-many relationship. Each Reference can be described by any number of descriptors. When the object model has been built, the navigation property functions like a collection of RefDescriptor instances. The navigation property builds as ObjectQuery in the programmable data model.

The End and Role definitions in this association are synonymous.

Implementation of Many-to-Many Association

Because any number of References can be related to any number of Contacts, the association between these entities must be implemented as a many-to-many association. The many-to-many association requires a link table in the storage implementation and an entity declaration in both the conceptual schema and storage metadata to represent the link table. Associations are then declared between the link entity and both the Contact entity and the Reference entity.

The following entity declaration in the CSDL uses a link table in the database. A similar declaration in the store schema definition language (SSDL) provides metadata on the link table.

  <EntityType Name="ContactPersonReference">
    <Key>
      <PropertyRef Name="ContactPersonRefID" />
    </Key>
    <Property Name="ContactPersonRefID" Type="Guid" Nullable="false" />
      <NavigationProperty Name="RelatedReference"
          Relationship="Self.LinkTable_Reference"
          FromRole="ContactPersonReference" ToRole="Reference" />
      <NavigationProperty Name="RelatedContact"
          Relationship="Self.LinkTable_ContactPerson"
          FromRole="ContactPersonReference" ToRole="ContactPerson" />
  </EntityType>

The identity Key is the only declared property in this schema. Navigation properties represent collections of related Reference instances and related ContactPerson instances. In the data table, there are columns that contain pairs of ReferenceID and ContactPersonID GUIDs.

Two associations support the many-to-many relationship: LinkTable_Reference and LinkTable_ContactPerson. These associations are defined in the following syntax:

  <AssociationSet Name="LinkTable_Reference"
      Association="ResearchCollaborationDataModel.LinkTable_Reference">
    <End Role="Reference" EntitySet="Reference" />
    <End Role="ContactPersonReference"
       EntitySet="ContactPersonReference" />
  </AssociationSet>

  <Association Name="LinkTable_ContactPerson">
    <End Role="ContactPerson" Type="ResearchCollaborationDataModel.ContactPerson" Multiplicity="1" />
    <End Role="ContactPersonReference"
       Type="ResearchCollaborationDataModel.ContactPersonReference"
       Multiplicity="*" />
  </Association>

Each of these associations is defined as one-to-many, but the navigation properties on the link entity connect collections of Reference/ContactPerson pairs.

Complete Schemas and Mapping Specification

The complete schemas and mapping specification used by this example can be downloaded from the ADO.NET Entity Framework Documentation Samples resource page in MSDN Code Gallery. Requirements and instructions for building and running the sample are provided in the readme.htm file in the download package. A script is also provided with the downloadable project that can be used to create the database for this example.

See Also

Concepts

Annotation and Research Collaboration Tool (EDM Sample Application)
Annotation Research Tool Application Code (EDM Sample Application)
Association (EDM)
Entity Type (EDM)

Other Resources

EDM Specifications
Schemas and Mapping Specification (Entity Framework)