Compartir a través de


How to: Manually Define an Entity Data Model (Entity Framework)

This topic shows how to manually create the mapping files that define the AdventureWorks Sales Entity Data Model (EDM). The AdventureWorks Sales Model is a subset of the complete AdventureWorks model that is used throughout the task-related topics in the Entity Framework documentation. If you manually generate mapping files, you will still have to configure your Visual Studio project to use the Entity Framework. For more information, see How to: Manually Configure an Entity Framework Project.

Note

If you use the Entity Data Model Wizard in a Visual Studio project, it automatically generates an Entity Data Model (EDM) and configures the project to use the Entity Framework. For more information, see How to: Use the Entity Data Model Wizard (Entity Framework).

To create the store schema definition language (SSDL) file

  • Add a file called AdventureWorks.ssdl to your project directory and paste in the following content:

    <Schema Namespace="AdventureWorksModel.Store" Alias="Self" Provider="System.Data.SqlClient" ProviderManifestToken="2005" xmlns:store="https://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns="https://schemas.microsoft.com/ado/2006/04/edm/ssdl">
      <EntityContainer Name="AdventureWorksModelStoreContainer">
        <EntitySet Name="Address" EntityType="AdventureWorksModel.Store.Address" store:Type="Tables" Schema="Person" />
        <EntitySet Name="Contact" EntityType="AdventureWorksModel.Store.Contact" store:Type="Tables" Schema="Person" />
        <EntitySet Name="Product" EntityType="AdventureWorksModel.Store.Product" store:Type="Tables" Schema="Production" />
        <EntitySet Name="SalesOrderDetail" EntityType="AdventureWorksModel.Store.SalesOrderDetail" store:Type="Tables" Schema="Sales" />
        <EntitySet Name="SalesOrderHeader" EntityType="AdventureWorksModel.Store.SalesOrderHeader" store:Type="Tables" Schema="Sales" />
        <AssociationSet Name="FK_SalesOrderDetail_SalesOrderHeader_SalesOrderID" Association="AdventureWorksModel.Store.FK_SalesOrderDetail_SalesOrderHeader_SalesOrderID">
          <End Role="SalesOrderHeader" EntitySet="SalesOrderHeader" />
          <End Role="SalesOrderDetail" EntitySet="SalesOrderDetail" />
        </AssociationSet>
        <AssociationSet Name="FK_SalesOrderHeader_Address_BillToAddressID" Association="AdventureWorksModel.Store.FK_SalesOrderHeader_Address_BillToAddressID">
          <End Role="Address" EntitySet="Address" />
          <End Role="SalesOrderHeader" EntitySet="SalesOrderHeader" />
        </AssociationSet>
        <AssociationSet Name="FK_SalesOrderHeader_Address_ShipToAddressID" Association="AdventureWorksModel.Store.FK_SalesOrderHeader_Address_ShipToAddressID">
          <End Role="Address" EntitySet="Address" />
          <End Role="SalesOrderHeader" EntitySet="SalesOrderHeader" />
        </AssociationSet>
        <AssociationSet Name="FK_SalesOrderHeader_Contact_ContactID" Association="AdventureWorksModel.Store.FK_SalesOrderHeader_Contact_ContactID">
          <End Role="Contact" EntitySet="Contact" />
          <End Role="SalesOrderHeader" EntitySet="SalesOrderHeader" />
        </AssociationSet>
      </EntityContainer>
      <EntityType Name="Address">
        <Key>
          <PropertyRef Name="AddressID" />
        </Key>
        <Property Name="AddressID" Type="int" Nullable="false" StoreGeneratedPattern="Identity" />
        <Property Name="AddressLine1" Type="nvarchar" Nullable="false" MaxLength="60" />
        <Property Name="AddressLine2" Type="nvarchar" MaxLength="60" />
        <Property Name="City" Type="nvarchar" Nullable="false" MaxLength="30" />
        <Property Name="StateProvinceID" Type="int" Nullable="false" />
        <Property Name="PostalCode" Type="nvarchar" Nullable="false" MaxLength="15" />
        <Property Name="rowguid" Type="uniqueidentifier" Nullable="false" />
        <Property Name="ModifiedDate" Type="datetime" Nullable="false" />
      </EntityType>
      <EntityType Name="Contact">
        <Key>
          <PropertyRef Name="ContactID" />
        </Key>
        <Property Name="ContactID" Type="int" Nullable="false" StoreGeneratedPattern="Identity" />
        <Property Name="NameStyle" Type="bit" Nullable="false" />
        <Property Name="Title" Type="nvarchar" MaxLength="8" />
        <Property Name="FirstName" Type="nvarchar" Nullable="false" MaxLength="50" />
        <Property Name="MiddleName" Type="nvarchar" MaxLength="50" />
        <Property Name="LastName" Type="nvarchar" Nullable="false" MaxLength="50" />
        <Property Name="Suffix" Type="nvarchar" MaxLength="10" />
        <Property Name="EmailAddress" Type="nvarchar" MaxLength="50" />
        <Property Name="EmailPromotion" Type="int" Nullable="false" />
        <Property Name="Phone" Type="nvarchar" MaxLength="25" />
        <Property Name="PasswordHash" Type="varchar" Nullable="false" MaxLength="40" />
        <Property Name="PasswordSalt" Type="varchar" Nullable="false" MaxLength="10" />
        <Property Name="AdditionalContactInfo" Type="xml" />
        <Property Name="rowguid" Type="uniqueidentifier" Nullable="false" />
        <Property Name="ModifiedDate" Type="datetime" Nullable="false" />
      </EntityType>
      <EntityType Name="Product">
        <Key>
          <PropertyRef Name="ProductID" />
        </Key>
        <Property Name="ProductID" Type="int" Nullable="false" StoreGeneratedPattern="Identity" />
        <Property Name="Name" Type="nvarchar" Nullable="false" MaxLength="50" />
        <Property Name="ProductNumber" Type="nvarchar" Nullable="false" MaxLength="25" />
        <Property Name="MakeFlag" Type="bit" Nullable="false" />
        <Property Name="FinishedGoodsFlag" Type="bit" Nullable="false" />
        <Property Name="Color" Type="nvarchar" MaxLength="15" />
        <Property Name="SafetyStockLevel" Type="smallint" Nullable="false" />
        <Property Name="ReorderPoint" Type="smallint" Nullable="false" />
        <Property Name="StandardCost" Type="money" Nullable="false" />
        <Property Name="ListPrice" Type="money" Nullable="false" />
        <Property Name="Size" Type="nvarchar" MaxLength="5" />
        <Property Name="SizeUnitMeasureCode" Type="nchar" MaxLength="3" />
        <Property Name="WeightUnitMeasureCode" Type="nchar" MaxLength="3" />
        <Property Name="Weight" Type="decimal" Precision="8" Scale="2" />
        <Property Name="DaysToManufacture" Type="int" Nullable="false" />
        <Property Name="ProductLine" Type="nchar" MaxLength="2" />
        <Property Name="Class" Type="nchar" MaxLength="2" />
        <Property Name="Style" Type="nchar" MaxLength="2" />
        <Property Name="ProductSubcategoryID" Type="int" />
        <Property Name="ProductModelID" Type="int" />
        <Property Name="SellStartDate" Type="datetime" Nullable="false" />
        <Property Name="SellEndDate" Type="datetime" />
        <Property Name="DiscontinuedDate" Type="datetime" />
        <Property Name="rowguid" Type="uniqueidentifier" Nullable="false" />
        <Property Name="ModifiedDate" Type="datetime" Nullable="false" />
      </EntityType>
      <EntityType Name="SalesOrderDetail">
        <Key>
          <PropertyRef Name="SalesOrderID" />
          <PropertyRef Name="SalesOrderDetailID" />
        </Key>
        <Property Name="SalesOrderID" Type="int" Nullable="false" />
        <Property Name="SalesOrderDetailID" Type="int" Nullable="false" StoreGeneratedPattern="Identity" />
        <Property Name="CarrierTrackingNumber" Type="nvarchar" MaxLength="25" />
        <Property Name="OrderQty" Type="smallint" Nullable="false" />
        <Property Name="ProductID" Type="int" Nullable="false" />
        <Property Name="SpecialOfferID" Type="int" Nullable="false" />
        <Property Name="UnitPrice" Type="money" Nullable="false" />
        <Property Name="UnitPriceDiscount" Type="money" Nullable="false" />
        <Property Name="LineTotal" Type="numeric" Nullable="false" Precision="38" Scale="6" StoreGeneratedPattern="Computed" />
        <Property Name="rowguid" Type="uniqueidentifier" Nullable="false" />
        <Property Name="ModifiedDate" Type="datetime" Nullable="false" />
      </EntityType>
      <EntityType Name="SalesOrderHeader">
        <Key>
          <PropertyRef Name="SalesOrderID" />
        </Key>
        <Property Name="SalesOrderID" Type="int" Nullable="false" StoreGeneratedPattern="Identity" />
        <Property Name="RevisionNumber" Type="tinyint" Nullable="false" />
        <Property Name="OrderDate" Type="datetime" Nullable="false" />
        <Property Name="DueDate" Type="datetime" Nullable="false" />
        <Property Name="ShipDate" Type="datetime" />
        <Property Name="Status" Type="tinyint" Nullable="false" />
        <Property Name="OnlineOrderFlag" Type="bit" Nullable="false" />
        <Property Name="SalesOrderNumber" Type="nvarchar" Nullable="false" MaxLength="25" StoreGeneratedPattern="Computed" />
        <Property Name="PurchaseOrderNumber" Type="nvarchar" MaxLength="25" />
        <Property Name="AccountNumber" Type="nvarchar" MaxLength="15" />
        <Property Name="CustomerID" Type="int" Nullable="false" />
        <Property Name="ContactID" Type="int" Nullable="false" />
        <Property Name="SalesPersonID" Type="int" />
        <Property Name="TerritoryID" Type="int" />
        <Property Name="BillToAddressID" Type="int" Nullable="false" />
        <Property Name="ShipToAddressID" Type="int" Nullable="false" />
        <Property Name="ShipMethodID" Type="int" Nullable="false" />
        <Property Name="CreditCardID" Type="int" />
        <Property Name="CreditCardApprovalCode" Type="varchar" MaxLength="15" />
        <Property Name="CurrencyRateID" Type="int" />
        <Property Name="SubTotal" Type="money" Nullable="false" />
        <Property Name="TaxAmt" Type="money" Nullable="false" />
        <Property Name="Freight" Type="money" Nullable="false" />
        <Property Name="TotalDue" Type="money" Nullable="false" StoreGeneratedPattern="Computed" />
        <Property Name="Comment" Type="nvarchar" MaxLength="128" />
        <Property Name="rowguid" Type="uniqueidentifier" Nullable="false" />
        <Property Name="ModifiedDate" Type="datetime" Nullable="false" />
      </EntityType>
      <Association Name="FK_SalesOrderDetail_SalesOrderHeader_SalesOrderID">
        <End Role="SalesOrderHeader" Type="AdventureWorksModel.Store.SalesOrderHeader" Multiplicity="1">
          <OnDelete Action="Cascade" />
        </End>
        <End Role="SalesOrderDetail" Type="AdventureWorksModel.Store.SalesOrderDetail" Multiplicity="*" />
        <ReferentialConstraint>
          <Principal Role="SalesOrderHeader">
            <PropertyRef Name="SalesOrderID" />
          </Principal>
          <Dependent Role="SalesOrderDetail">
            <PropertyRef Name="SalesOrderID" />
          </Dependent>
        </ReferentialConstraint>
      </Association>
      <Association Name="FK_SalesOrderHeader_Address_BillToAddressID">
        <End Role="Address" Type="AdventureWorksModel.Store.Address" Multiplicity="1" />
        <End Role="SalesOrderHeader" Type="AdventureWorksModel.Store.SalesOrderHeader" Multiplicity="*" />
        <ReferentialConstraint>
          <Principal Role="Address">
            <PropertyRef Name="AddressID" />
          </Principal>
          <Dependent Role="SalesOrderHeader">
            <PropertyRef Name="BillToAddressID" />
          </Dependent>
        </ReferentialConstraint>
      </Association>
      <Association Name="FK_SalesOrderHeader_Address_ShipToAddressID">
        <End Role="Address" Type="AdventureWorksModel.Store.Address" Multiplicity="1" />
        <End Role="SalesOrderHeader" Type="AdventureWorksModel.Store.SalesOrderHeader" Multiplicity="*" />
        <ReferentialConstraint>
          <Principal Role="Address">
            <PropertyRef Name="AddressID" />
          </Principal>
          <Dependent Role="SalesOrderHeader">
            <PropertyRef Name="ShipToAddressID" />
          </Dependent>
        </ReferentialConstraint>
      </Association>
      <Association Name="FK_SalesOrderHeader_Contact_ContactID">
        <End Role="Contact" Type="AdventureWorksModel.Store.Contact" Multiplicity="1" />
        <End Role="SalesOrderHeader" Type="AdventureWorksModel.Store.SalesOrderHeader" Multiplicity="*" />
        <ReferentialConstraint>
          <Principal Role="Contact">
            <PropertyRef Name="ContactID" />
          </Principal>
          <Dependent Role="SalesOrderHeader">
            <PropertyRef Name="ContactID" />
          </Dependent>
        </ReferentialConstraint>
      </Association>
    </Schema>
    

To create the conceptual schema definition language (CSDL) file

  • Add a file called AdventureWorks.csdl to your project directory and paste in the following content:

    <Schema Namespace="AdventureWorksModel" Alias="Self" xmlns="https://schemas.microsoft.com/ado/2006/04/edm">
      <EntityContainer Name="AdventureWorksEntities">
        <EntitySet Name="Address" EntityType="AdventureWorksModel.Address" />
        <EntitySet Name="Contact" EntityType="AdventureWorksModel.Contact" />
        <EntitySet Name="Product" EntityType="AdventureWorksModel.Product" />
        <EntitySet Name="SalesOrderDetail" EntityType="AdventureWorksModel.SalesOrderDetail" />
        <EntitySet Name="SalesOrderHeader" EntityType="AdventureWorksModel.SalesOrderHeader" />
        <AssociationSet Name="FK_SalesOrderHeader_Address_BillToAddressID" Association="AdventureWorksModel.FK_SalesOrderHeader_Address_BillToAddressID">
          <End Role="Address" EntitySet="Address" />
          <End Role="SalesOrderHeader" EntitySet="SalesOrderHeader" />
        </AssociationSet>
        <AssociationSet Name="FK_SalesOrderHeader_Address_ShipToAddressID" Association="AdventureWorksModel.FK_SalesOrderHeader_Address_ShipToAddressID">
          <End Role="Address" EntitySet="Address" />
          <End Role="SalesOrderHeader" EntitySet="SalesOrderHeader" />
        </AssociationSet>
        <AssociationSet Name="FK_SalesOrderHeader_Contact_ContactID" Association="AdventureWorksModel.FK_SalesOrderHeader_Contact_ContactID">
          <End Role="Contact" EntitySet="Contact" />
          <End Role="SalesOrderHeader" EntitySet="SalesOrderHeader" />
        </AssociationSet>
        <AssociationSet Name="FK_SalesOrderDetail_SalesOrderHeader_SalesOrderID" Association="AdventureWorksModel.FK_SalesOrderDetail_SalesOrderHeader_SalesOrderID">
          <End Role="SalesOrderHeader" EntitySet="SalesOrderHeader" />
          <End Role="SalesOrderDetail" EntitySet="SalesOrderDetail" />
        </AssociationSet>
      </EntityContainer>
      <EntityType Name="Address">
        <Key>
          <PropertyRef Name="AddressID" />
        </Key>
        <Property Name="AddressID" Type="Int32" Nullable="false" />
        <Property Name="AddressLine1" Type="String" Nullable="false" MaxLength="60" Unicode="true" FixedLength="false" />
        <Property Name="AddressLine2" Type="String" MaxLength="60" Unicode="true" FixedLength="false" />
        <Property Name="City" Type="String" Nullable="false" MaxLength="30" Unicode="true" FixedLength="false" />
        <Property Name="StateProvinceID" Type="Int32" Nullable="false" />
        <Property Name="PostalCode" Type="String" Nullable="false" MaxLength="15" Unicode="true" FixedLength="false" />
        <Property Name="rowguid" Type="Guid" Nullable="false" />
        <Property Name="ModifiedDate" Type="DateTime" Nullable="false" />
        <NavigationProperty Name="SalesOrderHeader" Relationship="AdventureWorksModel.FK_SalesOrderHeader_Address_BillToAddressID" FromRole="Address" ToRole="SalesOrderHeader" />
        <NavigationProperty Name="SalesOrderHeader1" Relationship="AdventureWorksModel.FK_SalesOrderHeader_Address_ShipToAddressID" FromRole="Address" ToRole="SalesOrderHeader" />
      </EntityType>
      <EntityType Name="Contact">
        <Key>
          <PropertyRef Name="ContactID" />
        </Key>
        <Property Name="ContactID" Type="Int32" Nullable="false" />
        <Property Name="NameStyle" Type="Boolean" Nullable="false" />
        <Property Name="Title" Type="String" MaxLength="8" Unicode="true" FixedLength="false" />
        <Property Name="FirstName" Type="String" Nullable="false" MaxLength="50" Unicode="true" FixedLength="false" />
        <Property Name="MiddleName" Type="String" MaxLength="50" Unicode="true" FixedLength="false" />
        <Property Name="LastName" Type="String" Nullable="false" MaxLength="50" Unicode="true" FixedLength="false" />
        <Property Name="Suffix" Type="String" MaxLength="10" Unicode="true" FixedLength="false" />
        <Property Name="EmailAddress" Type="String" MaxLength="50" Unicode="true" FixedLength="false" />
        <Property Name="EmailPromotion" Type="Int32" Nullable="false" />
        <Property Name="Phone" Type="String" MaxLength="25" Unicode="true" FixedLength="false" />
        <Property Name="PasswordHash" Type="String" Nullable="false" MaxLength="40" Unicode="false" FixedLength="false" />
        <Property Name="PasswordSalt" Type="String" Nullable="false" MaxLength="10" Unicode="false" FixedLength="false" />
        <Property Name="AdditionalContactInfo" Type="String" MaxLength="Max" Unicode="true" FixedLength="false" />
        <Property Name="rowguid" Type="Guid" Nullable="false" />
        <Property Name="ModifiedDate" Type="DateTime" Nullable="false" />
        <NavigationProperty Name="SalesOrderHeader" Relationship="AdventureWorksModel.FK_SalesOrderHeader_Contact_ContactID" FromRole="Contact" ToRole="SalesOrderHeader" />
      </EntityType>
      <EntityType Name="Product">
        <Key>
          <PropertyRef Name="ProductID" />
        </Key>
        <Property Name="ProductID" Type="Int32" Nullable="false" />
        <Property Name="Name" Type="String" Nullable="false" MaxLength="50" Unicode="true" FixedLength="false" />
        <Property Name="ProductNumber" Type="String" Nullable="false" MaxLength="25" Unicode="true" FixedLength="false" />
        <Property Name="MakeFlag" Type="Boolean" Nullable="false" />
        <Property Name="FinishedGoodsFlag" Type="Boolean" Nullable="false" />
        <Property Name="Color" Type="String" MaxLength="15" Unicode="true" FixedLength="false" />
        <Property Name="SafetyStockLevel" Type="Int16" Nullable="false" />
        <Property Name="ReorderPoint" Type="Int16" Nullable="false" />
        <Property Name="StandardCost" Type="Decimal" Nullable="false" Precision="19" Scale="4" />
        <Property Name="ListPrice" Type="Decimal" Nullable="false" Precision="19" Scale="4" />
        <Property Name="Size" Type="String" MaxLength="5" Unicode="true" FixedLength="false" />
        <Property Name="SizeUnitMeasureCode" Type="String" MaxLength="3" Unicode="true" FixedLength="true" />
        <Property Name="WeightUnitMeasureCode" Type="String" MaxLength="3" Unicode="true" FixedLength="true" />
        <Property Name="Weight" Type="Decimal" Precision="8" Scale="2" />
        <Property Name="DaysToManufacture" Type="Int32" Nullable="false" />
        <Property Name="ProductLine" Type="String" MaxLength="2" Unicode="true" FixedLength="true" />
        <Property Name="Class" Type="String" MaxLength="2" Unicode="true" FixedLength="true" />
        <Property Name="Style" Type="String" MaxLength="2" Unicode="true" FixedLength="true" />
        <Property Name="ProductSubcategoryID" Type="Int32" />
        <Property Name="ProductModelID" Type="Int32" />
        <Property Name="SellStartDate" Type="DateTime" Nullable="false" />
        <Property Name="SellEndDate" Type="DateTime" />
        <Property Name="DiscontinuedDate" Type="DateTime" />
        <Property Name="rowguid" Type="Guid" Nullable="false" />
        <Property Name="ModifiedDate" Type="DateTime" Nullable="false" />
      </EntityType>
      <EntityType Name="SalesOrderDetail">
        <Key>
          <PropertyRef Name="SalesOrderID" />
          <PropertyRef Name="SalesOrderDetailID" />
        </Key>
        <Property Name="SalesOrderID" Type="Int32" Nullable="false" />
        <Property Name="SalesOrderDetailID" Type="Int32" Nullable="false" />
        <Property Name="CarrierTrackingNumber" Type="String" MaxLength="25" Unicode="true" FixedLength="false" />
        <Property Name="OrderQty" Type="Int16" Nullable="false" />
        <Property Name="ProductID" Type="Int32" Nullable="false" />
        <Property Name="SpecialOfferID" Type="Int32" Nullable="false" />
        <Property Name="UnitPrice" Type="Decimal" Nullable="false" Precision="19" Scale="4" />
        <Property Name="UnitPriceDiscount" Type="Decimal" Nullable="false" Precision="19" Scale="4" />
        <Property Name="LineTotal" Type="Decimal" Nullable="false" Precision="38" Scale="6" />
        <Property Name="rowguid" Type="Guid" Nullable="false" />
        <Property Name="ModifiedDate" Type="DateTime" Nullable="false" />
        <NavigationProperty Name="SalesOrderHeader" Relationship="AdventureWorksModel.FK_SalesOrderDetail_SalesOrderHeader_SalesOrderID" FromRole="SalesOrderDetail" ToRole="SalesOrderHeader" />
      </EntityType>
      <EntityType Name="SalesOrderHeader">
        <Key>
          <PropertyRef Name="SalesOrderID" />
        </Key>
        <Property Name="SalesOrderID" Type="Int32" Nullable="false" />
        <Property Name="RevisionNumber" Type="Byte" Nullable="false" />
        <Property Name="OrderDate" Type="DateTime" Nullable="false" />
        <Property Name="DueDate" Type="DateTime" Nullable="false" />
        <Property Name="ShipDate" Type="DateTime" />
        <Property Name="Status" Type="Byte" Nullable="false" ConcurrencyMode="Fixed" />
        <Property Name="OnlineOrderFlag" Type="Boolean" Nullable="false" />
        <Property Name="SalesOrderNumber" Type="String" Nullable="false" MaxLength="25" Unicode="true" FixedLength="false" />
        <Property Name="PurchaseOrderNumber" Type="String" MaxLength="25" Unicode="true" FixedLength="false" />
        <Property Name="AccountNumber" Type="String" MaxLength="15" Unicode="true" FixedLength="false" />
        <Property Name="CustomerID" Type="Int32" Nullable="false" />
        <Property Name="SalesPersonID" Type="Int32" />
        <Property Name="TerritoryID" Type="Int32" />
        <Property Name="ShipMethodID" Type="Int32" Nullable="false" />
        <Property Name="CreditCardID" Type="Int32" />
        <Property Name="CreditCardApprovalCode" Type="String" MaxLength="15" Unicode="false" FixedLength="false" />
        <Property Name="CurrencyRateID" Type="Int32" />
        <Property Name="SubTotal" Type="Decimal" Nullable="false" Precision="19" Scale="4" />
        <Property Name="TaxAmt" Type="Decimal" Nullable="false" Precision="19" Scale="4" />
        <Property Name="Freight" Type="Decimal" Nullable="false" Precision="19" Scale="4" />
        <Property Name="TotalDue" Type="Decimal" Nullable="false" Precision="19" Scale="4" />
        <Property Name="Comment" Type="String" MaxLength="128" Unicode="true" FixedLength="false" />
        <Property Name="rowguid" Type="Guid" Nullable="false" />
        <Property Name="ModifiedDate" Type="DateTime" Nullable="false" />
        <NavigationProperty Name="Address" Relationship="AdventureWorksModel.FK_SalesOrderHeader_Address_BillToAddressID" FromRole="SalesOrderHeader" ToRole="Address" />
        <NavigationProperty Name="Address1" Relationship="AdventureWorksModel.FK_SalesOrderHeader_Address_ShipToAddressID" FromRole="SalesOrderHeader" ToRole="Address" />
        <NavigationProperty Name="Contact" Relationship="AdventureWorksModel.FK_SalesOrderHeader_Contact_ContactID" FromRole="SalesOrderHeader" ToRole="Contact" />
        <NavigationProperty Name="SalesOrderDetail" Relationship="AdventureWorksModel.FK_SalesOrderDetail_SalesOrderHeader_SalesOrderID" FromRole="SalesOrderHeader" ToRole="SalesOrderDetail" />
      </EntityType>
      <Association Name="FK_SalesOrderHeader_Address_BillToAddressID">
        <End Role="Address" Type="AdventureWorksModel.Address" Multiplicity="1" />
        <End Role="SalesOrderHeader" Type="AdventureWorksModel.SalesOrderHeader" Multiplicity="*" />
      </Association>
      <Association Name="FK_SalesOrderHeader_Address_ShipToAddressID">
        <End Role="Address" Type="AdventureWorksModel.Address" Multiplicity="1" />
        <End Role="SalesOrderHeader" Type="AdventureWorksModel.SalesOrderHeader" Multiplicity="*" />
      </Association>
      <Association Name="FK_SalesOrderHeader_Contact_ContactID">
        <End Role="Contact" Type="AdventureWorksModel.Contact" Multiplicity="1" />
        <End Role="SalesOrderHeader" Type="AdventureWorksModel.SalesOrderHeader" Multiplicity="*" />
      </Association>
      <Association Name="FK_SalesOrderDetail_SalesOrderHeader_SalesOrderID">
        <End Role="SalesOrderHeader" Type="AdventureWorksModel.SalesOrderHeader" Multiplicity="1">
          <OnDelete Action="Cascade" />
        </End>
        <End Role="SalesOrderDetail" Type="AdventureWorksModel.SalesOrderDetail" Multiplicity="*" />
        <ReferentialConstraint>
          <Principal Role="SalesOrderHeader">
            <PropertyRef Name="SalesOrderID" />
          </Principal>
          <Dependent Role="SalesOrderDetail">
            <PropertyRef Name="SalesOrderID" />
          </Dependent>
        </ReferentialConstraint>
      </Association>
    </Schema>
    

To create the mapping specification language (MSL) file

  • Add a file called AdventureWorks.msl to your project directory and paste in the following content:

    <Mapping Space="C-S" xmlns="urn:schemas-microsoft-com:windows:storage:mapping:CS">
      <EntityContainerMapping StorageEntityContainer="AdventureWorksModelStoreContainer" CdmEntityContainer="AdventureWorksEntities">
        <EntitySetMapping Name="Address">
          <EntityTypeMapping TypeName="IsTypeOf(AdventureWorksModel.Address)">
            <MappingFragment StoreEntitySet="Address">
              <ScalarProperty Name="AddressID" ColumnName="AddressID" />
              <ScalarProperty Name="AddressLine1" ColumnName="AddressLine1" />
              <ScalarProperty Name="AddressLine2" ColumnName="AddressLine2" />
              <ScalarProperty Name="City" ColumnName="City" />
              <ScalarProperty Name="StateProvinceID" ColumnName="StateProvinceID" />
              <ScalarProperty Name="PostalCode" ColumnName="PostalCode" />
              <ScalarProperty Name="rowguid" ColumnName="rowguid" />
              <ScalarProperty Name="ModifiedDate" ColumnName="ModifiedDate" />
            </MappingFragment>
          </EntityTypeMapping>
        </EntitySetMapping>
        <EntitySetMapping Name="Contact">
          <EntityTypeMapping TypeName="IsTypeOf(AdventureWorksModel.Contact)">
            <MappingFragment StoreEntitySet="Contact">
              <ScalarProperty Name="ContactID" ColumnName="ContactID" />
              <ScalarProperty Name="NameStyle" ColumnName="NameStyle" />
              <ScalarProperty Name="Title" ColumnName="Title" />
              <ScalarProperty Name="FirstName" ColumnName="FirstName" />
              <ScalarProperty Name="MiddleName" ColumnName="MiddleName" />
              <ScalarProperty Name="LastName" ColumnName="LastName" />
              <ScalarProperty Name="Suffix" ColumnName="Suffix" />
              <ScalarProperty Name="EmailAddress" ColumnName="EmailAddress" />
              <ScalarProperty Name="EmailPromotion" ColumnName="EmailPromotion" />
              <ScalarProperty Name="Phone" ColumnName="Phone" />
              <ScalarProperty Name="PasswordHash" ColumnName="PasswordHash" />
              <ScalarProperty Name="PasswordSalt" ColumnName="PasswordSalt" />
              <ScalarProperty Name="AdditionalContactInfo" ColumnName="AdditionalContactInfo" />
              <ScalarProperty Name="rowguid" ColumnName="rowguid" />
              <ScalarProperty Name="ModifiedDate" ColumnName="ModifiedDate" />
            </MappingFragment>
          </EntityTypeMapping>
        </EntitySetMapping>
        <EntitySetMapping Name="Product">
          <EntityTypeMapping TypeName="IsTypeOf(AdventureWorksModel.Product)">
            <MappingFragment StoreEntitySet="Product">
              <ScalarProperty Name="ProductID" ColumnName="ProductID" />
              <ScalarProperty Name="Name" ColumnName="Name" />
              <ScalarProperty Name="ProductNumber" ColumnName="ProductNumber" />
              <ScalarProperty Name="MakeFlag" ColumnName="MakeFlag" />
              <ScalarProperty Name="FinishedGoodsFlag" ColumnName="FinishedGoodsFlag" />
              <ScalarProperty Name="Color" ColumnName="Color" />
              <ScalarProperty Name="SafetyStockLevel" ColumnName="SafetyStockLevel" />
              <ScalarProperty Name="ReorderPoint" ColumnName="ReorderPoint" />
              <ScalarProperty Name="StandardCost" ColumnName="StandardCost" />
              <ScalarProperty Name="ListPrice" ColumnName="ListPrice" />
              <ScalarProperty Name="Size" ColumnName="Size" />
              <ScalarProperty Name="SizeUnitMeasureCode" ColumnName="SizeUnitMeasureCode" />
              <ScalarProperty Name="WeightUnitMeasureCode" ColumnName="WeightUnitMeasureCode" />
              <ScalarProperty Name="Weight" ColumnName="Weight" />
              <ScalarProperty Name="DaysToManufacture" ColumnName="DaysToManufacture" />
              <ScalarProperty Name="ProductLine" ColumnName="ProductLine" />
              <ScalarProperty Name="Class" ColumnName="Class" />
              <ScalarProperty Name="Style" ColumnName="Style" />
              <ScalarProperty Name="ProductSubcategoryID" ColumnName="ProductSubcategoryID" />
              <ScalarProperty Name="ProductModelID" ColumnName="ProductModelID" />
              <ScalarProperty Name="SellStartDate" ColumnName="SellStartDate" />
              <ScalarProperty Name="SellEndDate" ColumnName="SellEndDate" />
              <ScalarProperty Name="DiscontinuedDate" ColumnName="DiscontinuedDate" />
              <ScalarProperty Name="rowguid" ColumnName="rowguid" />
              <ScalarProperty Name="ModifiedDate" ColumnName="ModifiedDate" />
            </MappingFragment>
          </EntityTypeMapping>
        </EntitySetMapping>
        <EntitySetMapping Name="SalesOrderDetail">
          <EntityTypeMapping TypeName="IsTypeOf(AdventureWorksModel.SalesOrderDetail)">
            <MappingFragment StoreEntitySet="SalesOrderDetail">
              <ScalarProperty Name="SalesOrderID" ColumnName="SalesOrderID" />
              <ScalarProperty Name="SalesOrderDetailID" ColumnName="SalesOrderDetailID" />
              <ScalarProperty Name="CarrierTrackingNumber" ColumnName="CarrierTrackingNumber" />
              <ScalarProperty Name="OrderQty" ColumnName="OrderQty" />
              <ScalarProperty Name="ProductID" ColumnName="ProductID" />
              <ScalarProperty Name="SpecialOfferID" ColumnName="SpecialOfferID" />
              <ScalarProperty Name="UnitPrice" ColumnName="UnitPrice" />
              <ScalarProperty Name="UnitPriceDiscount" ColumnName="UnitPriceDiscount" />
              <ScalarProperty Name="LineTotal" ColumnName="LineTotal" />
              <ScalarProperty Name="rowguid" ColumnName="rowguid" />
              <ScalarProperty Name="ModifiedDate" ColumnName="ModifiedDate" />
            </MappingFragment>
          </EntityTypeMapping>
        </EntitySetMapping>
        <EntitySetMapping Name="SalesOrderHeader">
          <EntityTypeMapping TypeName="IsTypeOf(AdventureWorksModel.SalesOrderHeader)">
            <MappingFragment StoreEntitySet="SalesOrderHeader">
              <ScalarProperty Name="SalesOrderID" ColumnName="SalesOrderID" />
              <ScalarProperty Name="RevisionNumber" ColumnName="RevisionNumber" />
              <ScalarProperty Name="OrderDate" ColumnName="OrderDate" />
              <ScalarProperty Name="DueDate" ColumnName="DueDate" />
              <ScalarProperty Name="ShipDate" ColumnName="ShipDate" />
              <ScalarProperty Name="Status" ColumnName="Status" />
              <ScalarProperty Name="OnlineOrderFlag" ColumnName="OnlineOrderFlag" />
              <ScalarProperty Name="SalesOrderNumber" ColumnName="SalesOrderNumber" />
              <ScalarProperty Name="PurchaseOrderNumber" ColumnName="PurchaseOrderNumber" />
              <ScalarProperty Name="AccountNumber" ColumnName="AccountNumber" />
              <ScalarProperty Name="CustomerID" ColumnName="CustomerID" />
              <ScalarProperty Name="SalesPersonID" ColumnName="SalesPersonID" />
              <ScalarProperty Name="TerritoryID" ColumnName="TerritoryID" />
              <ScalarProperty Name="ShipMethodID" ColumnName="ShipMethodID" />
              <ScalarProperty Name="CreditCardID" ColumnName="CreditCardID" />
              <ScalarProperty Name="CreditCardApprovalCode" ColumnName="CreditCardApprovalCode" />
              <ScalarProperty Name="CurrencyRateID" ColumnName="CurrencyRateID" />
              <ScalarProperty Name="SubTotal" ColumnName="SubTotal" />
              <ScalarProperty Name="TaxAmt" ColumnName="TaxAmt" />
              <ScalarProperty Name="Freight" ColumnName="Freight" />
              <ScalarProperty Name="TotalDue" ColumnName="TotalDue" />
              <ScalarProperty Name="Comment" ColumnName="Comment" />
              <ScalarProperty Name="rowguid" ColumnName="rowguid" />
              <ScalarProperty Name="ModifiedDate" ColumnName="ModifiedDate" />
            </MappingFragment>
          </EntityTypeMapping>
        </EntitySetMapping>
        <AssociationSetMapping Name="FK_SalesOrderHeader_Address_BillToAddressID" TypeName="AdventureWorksModel.FK_SalesOrderHeader_Address_BillToAddressID" StoreEntitySet="SalesOrderHeader">
          <EndProperty Name="Address">
            <ScalarProperty Name="AddressID" ColumnName="BillToAddressID" />
          </EndProperty>
          <EndProperty Name="SalesOrderHeader">
            <ScalarProperty Name="SalesOrderID" ColumnName="SalesOrderID" />
          </EndProperty>
        </AssociationSetMapping>
        <AssociationSetMapping Name="FK_SalesOrderHeader_Address_ShipToAddressID" TypeName="AdventureWorksModel.FK_SalesOrderHeader_Address_ShipToAddressID" StoreEntitySet="SalesOrderHeader">
          <EndProperty Name="Address">
            <ScalarProperty Name="AddressID" ColumnName="ShipToAddressID" />
          </EndProperty>
          <EndProperty Name="SalesOrderHeader">
            <ScalarProperty Name="SalesOrderID" ColumnName="SalesOrderID" />
          </EndProperty>
        </AssociationSetMapping>
        <AssociationSetMapping Name="FK_SalesOrderHeader_Contact_ContactID" TypeName="AdventureWorksModel.FK_SalesOrderHeader_Contact_ContactID" StoreEntitySet="SalesOrderHeader">
          <EndProperty Name="Contact">
            <ScalarProperty Name="ContactID" ColumnName="ContactID" />
          </EndProperty>
          <EndProperty Name="SalesOrderHeader">
            <ScalarProperty Name="SalesOrderID" ColumnName="SalesOrderID" />
          </EndProperty>
        </AssociationSetMapping>
        <AssociationSetMapping Name="FK_SalesOrderDetail_SalesOrderHeader_SalesOrderID" TypeName="AdventureWorksModel.FK_SalesOrderDetail_SalesOrderHeader_SalesOrderID" StoreEntitySet="SalesOrderDetail">
          <EndProperty Name="SalesOrderHeader">
            <ScalarProperty Name="SalesOrderID" ColumnName="SalesOrderID" />
          </EndProperty>
          <EndProperty Name="SalesOrderDetail">
            <ScalarProperty Name="SalesOrderID" ColumnName="SalesOrderID" />
            <ScalarProperty Name="SalesOrderDetailID" ColumnName="SalesOrderDetailID" />
          </EndProperty>
        </AssociationSetMapping>
      </EntityContainerMapping>
    </Mapping>
    

See Also

Concepts

Quickstart (Entity Framework)

Other Resources

Schemas and Mapping Specification (Entity Framework)