Export (0) Print
Expand All

How to: Customize Modeling and Mapping Files to Work with Custom Objects

To use custom data classes with the Entity Framework, you must match the entity types and properties that are defined in the conceptual model to the custom data classes. When you use the Entity Data Model tools to generate the model and mapping content from a database, the entity types and entity sets in the conceptual model match the tables in the database. To update the model and mapping content to match the custom data classes, you must perform the following steps:

  1. Update the conceptual model content, which is defined in conceptual schema definition language (CSDL), to match the custom data classes.

  2. Update the storage model content, which is defined in store schema definition language (SSDL), if necessary.

  3. Update the mapping content, which is defined in mapping specification language (MSL).

  4. Validate the updated model and mapping content.

  5. Prevent Visual Studio from generating the object layer.

Bb738625.note(en-us,VS.100).gifNote:
The Entity Data Model tools can also generate scripts that create a new database based on storage schema definition (SSDL) content. In this case, you can create a data model that matches your custom data classes and then create a new database based on the .edmx file. For more information, see How to: Create a Database from a Conceptual Model.

This topic shows how to update the model by using the ADO.NET Entity Data Model Designer (Entity Designer) or the EDM Generator (EdmGen.exe) utility. To run the examples in this topic, you must have already generated your model. The model in this example is based on the Contact, SalesOrderHeader and SalesOrderDetail tables in the AdventureWorks database. For information about how to create a new model, see How to: Use the Entity Data Model Wizard or How to: Use EdmGen.exe to Generate the Model and Mapping Files. You must also add Contact, Orders, and LineItem custom data classes that map to the Contact, SalesOrderHeader, and SalesOrderDetail tables to your project. To define the Contact, Orders, and LineItem custom data classes , see How to: Define POCO Entities.

The following procedures assume that you have the .edmx file open in the Entity Designer.

Modify the model by using the Entity Data Model Designer.

  1. Rename the EntityType and EntitySet elements to reflect the names of the custom data classes.

    • Select the Contact entity. In the Properties window, and set Entity Set Name to ContactSet.

    • Select the SalesOrderHeader entity. In the Properties window, set Name to Order and Entity Set Name to OrderSet.

    • Select SalesOrderDetails. In the Properties window, set Name to LineItem and Entity Set Name to LineItemSet.

  2. Change the name of the navigation properties.

    • Select the SalesOrderHeaders navigation property of the Contact entity. In the Properties window, set Name to Orders.

    • Select the SalesOrderDetails navigation property of the SalesOrderHeader entity. In the Properties window, set Name to LineItems.

    • Select the SalesOrderHeader navigation property of the SalesOrderDetail entity. In the Properties window, set Name to Order.

  3. Change the association.

    • Select the association between Client and Order entity types and modify the following properties to match the following values in the Properties window:

      Association Set Name: Order_ Contact_ ContactIDSet

      End1 Navigation Property: Orders

      End1 Role Name: Contact

      End2 Navigation Property: Contact

      End2 Role Name: Order

      Name: Order_Contact_ContactID

    • Select the association between Order and LineItem entity types and modify the following properties to match the following values in the Properties window:

      Association Set Name: LineItem_Order_SalesOrderIDSet

      End1 Navigation Property: LineItems

      End1 Role Name: Order

      End2 Navigation Property: Order

      End2 Role Name: LineItem

      Name: LineItem_Order_SalesOrderID

  4. Create a complex type from the properties of the Order entity type.

    • Select the following properties of the Order entity: AccountNumber, Comment, PurchaseOrderNumber, and SalesOrderNumber, then right-click and select Create Complex Type.

      A new complex type with the selected properties is added to the Model Browser. A new complex type property is added to the SalesOrderHeader entity. The complex type and complex type property are given default names.

    • Rename the complex type to OrderInfo.

    • Rename the complex type property to ExtendedInfo.

  5. Save the changes to the .edmx file.

  6. Disable code generation for the .edmx file. Open the .edmx file in the ADO.NET Entity Data Model Designer (Entity Designer). Right-click on the designer surface and select Properties. In the Properties window, select the Code Generation Strategy property and select None. If the Properties window is not visible, press F4.

Modify the model by using EdmGen.exe.

  1. Open the CSDL file in Visual Studio or in a text editor.

    • Rename the EntityType and EntitySet elements to reflect the names of the custom data classes.

    • Rename the Property elements of each type to match the name of the properties in the custom data class.

    • Remove the Property elements for any properties that do not exist in the custom data class.

    • Rename the NavigationProperty element to match the name of the navigation property in the custom data class. Make sure the FromRole and ToRole point to the correct entity types.

    • Save the changes to the .csdl file.

  2. Open the MSL file in Visual Studio or in a text editor.

    • Rename the EntitySetMapping element and the TypeName attribute to reflect the names of the custom classes.

    • Remove the EntitySetMapping element for any entity that does not have a corresponding custom data class.

    • Rename the ScalarProperty elements of each type to match the names of the properties in the custom data class.

    • Remove the ScalarProperty element for any properties that do not exist in the custom data class.

    • Save the changes to the .msl file.

  3. Open the SSDL file in Visual Studio or in a text editor.

    • Remove the EntityType elements for any entities that are not mapped to custom data classes.

    • Remove the ScalarProperty elements for any properties that are not mapped to properties of the custom data classes.

    • Save the changes to the .ssdl file.

  4. Validate the updated mapping files by running the EdmGen.exe utility in the directory that contains the mapping files.

    • Use the following command:

      %windir%\Microsoft.NET\Framework\v4\edmgen.exe /mode:ValidateArtifacts  
      /inssdl:.\YourModel.ssdl /inmsl:.\YourModel.msl /incsdl:.\YourModel.csdl 
      
    Bb738625.note(en-us,VS.100).gifNote:
    Remove line breaks and replace YourModel with the name used for your mapping files.

    • Review the output and repair any validation errors.

  5. Regenerate, save, and remove autogenerated object code.

    • In Solution Explorer in Visual Studio, right-click the .csdl file and select Run Custom Tool.

    • This regenerates the object layer based on the modified .csdl file.

    • Expand the .csdl file node, open the designer file, and save the file as a different file name.

      This saves the autogenerated object layer file. Code from this file is used in the topic How to: Define a Custom Object Context.

    • Exclude the designer file from the project.

    • Select the .csdl file and clear the Custom Tool value in the Properties window.

      This will stop the object layer file from being regenerated. To generate this file in the future, type EntityModelCodeGenerator for Custom Tool in the Properties window and repeat step 1.

Example

The following .csdl file has been customized to support the Contact, Orders, and LineItem custom data classes.

<Schema Namespace="AdventureWorksModel" Alias="Self" xmlns:annotation="http://schemas.microsoft.com/ado/2009/02/edm/annotation" xmlns="http://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>

The following .msl file has been customized to map the Contact, Orders, and LineItem custom data classes to the Contact, SalesOrderHeader, and SalesOrderDetail tables in the AdventureWorks database.

<Mapping Space="C-S" xmlns="http://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>

The following .ssdl file has been customized to support the Contact, Orders, and LineItem custom data classes by using the Contact, SalesOrderHeader, and SalesOrderDetail tables in the AdventureWorks database.

<Schema Namespace="AdventureWorksModel.Store" Alias="Self" Provider="System.Data.SqlClient" ProviderManifestToken="2008" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns="http://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>

See Also

Community Additions

ADD
Show:
© 2014 Microsoft