Partilhar via


Custom AdventureWorks .edmx File

This example is based on the AdventureWorks data model that maps Contact, SalesOrderHeader, and SalesOrderDetail tables to Contact, Orders, and LineItem types. Instead of following the steps that define this model (described in How to: Customize Modeling and Mapping Files to Work with Custom Objects), you can create an empty model and edit the model in the editor. To edit the model, open the AdventureWorksModel.edmx file and copy the following code within the edmx:Runtime tags.

<!-- SSDL content -->
<edmx:StorageModels>
<Schema Namespace="AdventureWorksModel.Store" Alias="Self" Provider="System.Data.SqlClient" ProviderManifestToken="2008" xmlns:store="https://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns="https://schemas.microsoft.com/ado/2009/02/edm/ssdl">
    <EntityContainer Name="AdventureWorksModelStoreContainer">
      <EntitySet Name="Contact" EntityType="AdventureWorksModel.Store.Contact" store:Type="Tables" Schema="Person" />
      <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_Contact_ContactID" Association="AdventureWorksModel.Store.FK_SalesOrderHeader_Contact_ContactID">
        <End Role="Contact" EntitySet="Contact" />
        <End Role="SalesOrderHeader" EntitySet="SalesOrderHeader" />
      </AssociationSet>
    </EntityContainer>
    <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="128" />
      <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="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_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>
</edmx:StorageModels>
<!-- CSDL content -->
<edmx:ConceptualModels>
  <Schema Namespace="AdventureWorksModel" Alias="Self" xmlns:annotation="https://schemas.microsoft.com/ado/2009/02/edm/annotation" xmlns="https://schemas.microsoft.com/ado/2008/09/edm">
    <EntityContainer Name="AdventureWorksEntities" annotation:LazyLoadingEnabled="true">
      <EntitySet Name="LineItemSet" EntityType="AdventureWorksModel.LineItem" />
      <EntitySet Name="OrderSet" EntityType="AdventureWorksModel.Order" />
      <AssociationSet Name="LineItem_Order_SalesOrderIDSet" Association="AdventureWorksModel.LineItem_Order_SalesOrderID">
        <End Role="Order" EntitySet="OrderSet" />
        <End Role="LineItem" EntitySet="LineItemSet" />
      </AssociationSet>
    <EntitySet Name="ContactSet" EntityType="AdventureWorksModel.Contact" />
    <AssociationSet Name="Order_Contact_ContactID" Association="AdventureWorksModel.Order_Contact_ContactID">
    <End Role="Contact" EntitySet="ContactSet" />
    <End Role="Order" EntitySet="OrderSet" /></AssociationSet>
    </EntityContainer>
    <EntityType Name="LineItem">
      <Key>
        <PropertyRef Name="SalesOrderID" />
        <PropertyRef Name="SalesOrderDetailID" />
      </Key>
      <Property Name="SalesOrderID" Type="Int32" Nullable="false" />
      <Property Name="SalesOrderDetailID" Type="Int32" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
      <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" annotation:StoreGeneratedPattern="Computed" />
      <Property Name="rowguid" Type="Guid" Nullable="false" />
      <Property Name="ModifiedDate" Type="DateTime" Nullable="false" />
      <NavigationProperty Name="Order" Relationship="AdventureWorksModel.LineItem_Order_SalesOrderID" FromRole="LineItem" ToRole="Order" />
    </EntityType>
    <EntityType Name="Order">
      <Key>
        <PropertyRef Name="SalesOrderID" />
      </Key>
      <Property Name="SalesOrderID" Type="Int32" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
      <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" />
      <Property Name="OnlineOrderFlag" Type="Boolean" Nullable="false" />
      <Property Name="CustomerID" Type="Int32" Nullable="false" />
      <Property Name="ContactID" Type="Int32" Nullable="false" />
      <Property Name="SalesPersonID" Type="Int32" />
      <Property Name="TerritoryID" Type="Int32" />
      <Property Name="BillToAddressID" Type="Int32" Nullable="false" />
      <Property Name="ShipToAddressID" Type="Int32" Nullable="false" />
      <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" annotation:StoreGeneratedPattern="Computed" />
      <Property Name="rowguid" Type="Guid" Nullable="false" />
      <Property Name="ModifiedDate" Type="DateTime" Nullable="false" />
      <NavigationProperty Name="LineItems" Relationship="AdventureWorksModel.LineItem_Order_SalesOrderID" FromRole="Order" ToRole="LineItem" />
      <Property Name="ExtendedInfo" Type="AdventureWorksModel.OrderInfo" Nullable="false" />
      <NavigationProperty Name="Contact" Relationship="AdventureWorksModel.Order_Contact_ContactID" FromRole="Order" ToRole="Contact" />
      </EntityType>
    <Association Name="LineItem_Order_SalesOrderID">
      <End Role="Order" Type="AdventureWorksModel.Order" Multiplicity="1">
        <OnDelete Action="Cascade" />
      </End>
      <End Role="LineItem" Type="AdventureWorksModel.LineItem" Multiplicity="*" />
      <ReferentialConstraint>
        <Principal Role="Order">
          <PropertyRef Name="SalesOrderID" />
        </Principal>
        <Dependent Role="LineItem">
          <PropertyRef Name="SalesOrderID" />
        </Dependent>
      </ReferentialConstraint>
    </Association>
    <ComplexType Name="OrderInfo">
    <Property Type="String" Name="Comment" MaxLength="128" FixedLength="false" Unicode="true" />
    <Property Type="String" Name="AccountNumber" MaxLength="15" FixedLength="false" Unicode="true" />
    <Property Type="String" Name="PurchaseOrderNumber" MaxLength="25" FixedLength="false" Unicode="true" />
    <Property Type="String" Name="SalesOrderNumber" Nullable="false" MaxLength="25" FixedLength="false" Unicode="true" /></ComplexType>
    <EntityType Name="Contact">
    <Key>
    <PropertyRef Name="ContactID" /></Key>
    <Property Type="Int32" Name="ContactID" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
    <Property Type="Boolean" Name="NameStyle" Nullable="false" />
    <Property Type="String" Name="Title" MaxLength="8" FixedLength="false" Unicode="true" />
    <Property Type="String" Name="FirstName" Nullable="false" MaxLength="50" FixedLength="false" Unicode="true" />
    <Property Type="String" Name="MiddleName" MaxLength="50" FixedLength="false" Unicode="true" />
    <Property Type="String" Name="LastName" Nullable="false" MaxLength="50" FixedLength="false" Unicode="true" />
    <Property Type="String" Name="Suffix" MaxLength="10" FixedLength="false" Unicode="true" />
    <Property Type="String" Name="EmailAddress" MaxLength="50" FixedLength="false" Unicode="true" />
    <Property Type="Int32" Name="EmailPromotion" Nullable="false" />
    <Property Type="String" Name="Phone" MaxLength="25" FixedLength="false" Unicode="true" />
    <Property Type="String" Name="PasswordHash" Nullable="false" MaxLength="128" FixedLength="false" Unicode="false" />
    <Property Type="String" Name="PasswordSalt" Nullable="false" MaxLength="10" FixedLength="false" Unicode="false" />
    <Property Type="String" Name="AdditionalContactInfo" MaxLength="Max" FixedLength="false" Unicode="true" />
    <Property Type="Guid" Name="rowguid" Nullable="false" />
    <Property Type="DateTime" Name="ModifiedDate" Nullable="false" />
    <NavigationProperty Name="Orders" Relationship="AdventureWorksModel.Order_Contact_ContactID" FromRole="Contact" ToRole="Order" /></EntityType>
    <Association Name="Order_Contact_ContactID">
    <End Type="AdventureWorksModel.Contact" Role="Contact" Multiplicity="1" />
    <End Type="AdventureWorksModel.Order" Role="Order" Multiplicity="*" />
    <ReferentialConstraint>
    <Principal Role="Contact">
    <PropertyRef Name="ContactID" /></Principal>
    <Dependent Role="Order">
    <PropertyRef Name="ContactID" /></Dependent></ReferentialConstraint></Association>
    </Schema>
</edmx:ConceptualModels>
<!-- C-S mapping content -->
<edmx:Mappings>
  <Mapping Space="C-S" xmlns="https://schemas.microsoft.com/ado/2008/09/mapping/cs">
    <EntityContainerMapping StorageEntityContainer="AdventureWorksModelStoreContainer" CdmEntityContainer="AdventureWorksEntities">
      <EntitySetMapping Name="LineItemSet">
        <EntityTypeMapping TypeName="AdventureWorksModel.LineItem">
          <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="OrderSet">
        <EntityTypeMapping TypeName="AdventureWorksModel.Order">
          <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="CustomerID" ColumnName="CustomerID" />
            <ScalarProperty Name="ContactID" ColumnName="ContactID" />
            <ScalarProperty Name="SalesPersonID" ColumnName="SalesPersonID" />
            <ScalarProperty Name="TerritoryID" ColumnName="TerritoryID" />
            <ScalarProperty Name="BillToAddressID" ColumnName="BillToAddressID" />
            <ScalarProperty Name="ShipToAddressID" ColumnName="ShipToAddressID" />
            <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="rowguid" ColumnName="rowguid" />
            <ScalarProperty Name="ModifiedDate" ColumnName="ModifiedDate" />
            <ComplexProperty Name="ExtendedInfo">
              <ScalarProperty Name="SalesOrderNumber" ColumnName="SalesOrderNumber" />
              <ScalarProperty Name="PurchaseOrderNumber" ColumnName="PurchaseOrderNumber" />
              <ScalarProperty Name="AccountNumber" ColumnName="AccountNumber" />
              <ScalarProperty Name="Comment" ColumnName="Comment" />
            </ComplexProperty>
          </MappingFragment>
        </EntityTypeMapping>
      </EntitySetMapping>
        <EntitySetMapping Name="ContactSet">
        <EntityTypeMapping TypeName="AdventureWorksModel.Contact">
        <MappingFragment StoreEntitySet="Contact">
        <ScalarProperty Name="ModifiedDate" ColumnName="ModifiedDate" />
        <ScalarProperty Name="rowguid" ColumnName="rowguid" />
        <ScalarProperty Name="AdditionalContactInfo" ColumnName="AdditionalContactInfo" />
        <ScalarProperty Name="PasswordSalt" ColumnName="PasswordSalt" />
        <ScalarProperty Name="PasswordHash" ColumnName="PasswordHash" />
        <ScalarProperty Name="Phone" ColumnName="Phone" />
        <ScalarProperty Name="EmailPromotion" ColumnName="EmailPromotion" />
        <ScalarProperty Name="EmailAddress" ColumnName="EmailAddress" />
        <ScalarProperty Name="Suffix" ColumnName="Suffix" />
        <ScalarProperty Name="LastName" ColumnName="LastName" />
        <ScalarProperty Name="MiddleName" ColumnName="MiddleName" />
        <ScalarProperty Name="FirstName" ColumnName="FirstName" />
        <ScalarProperty Name="Title" ColumnName="Title" />
        <ScalarProperty Name="NameStyle" ColumnName="NameStyle" />
        <ScalarProperty Name="ContactID" ColumnName="ContactID" /></MappingFragment></EntityTypeMapping></EntitySetMapping>
    </EntityContainerMapping>
  </Mapping>
</edmx:Mappings>

See Also

Concepts

Working with POCO Entities