6 Appendix A: Sample Entity Data Model and CSDL Document
An Entity Data Model conceptual schema, as specified in [MC-CSDL], is an XML document written with the conceptual schema definition language (CSDL), which describes entities and the associations between entities.
The following example conceptual schema definition language (CSDL) document defines seven EntityTypes (Customer, Order, OrdersLine, Employee, Document, Company, and Photo), each with Primitive type properties and some with NavigationProperties (which refer to the associations between the entities and NamedStream properties). In the example conceptual schema definition language (CSDL) document, a 1-to-many association exists between Customer and Order entities and a 1-to-many association exists between Order and OrderLine entities.
The conceptual schema definition language (CSDL) document also defines a single FunctionImport, as described in [MC-CSDL], named "CustomersByCity", which returns a collection of Customer EntityType instances in a particular city.
All examples in this document use the conceptual schema definition language (CSDL) and sample data set defined below.
Sample Data:
A Customer EntityType instance exists with EntityKey value ALFKI.
A total of 91 Customer EntityType instances exist.
An Employee EntityType instance exists with EntityKey value 1.
Two Order EntityType instances exist, one with EntityKey value 1 and the other with EntityKey value 2. Order 1 and 2 are associated with Customer ALFKI.
Two OrderLine EntityType instances exist, one with EntityKey value 100 and the other with EntityKey value 200. OrderLine 100 is associated with Order 1 and OrderLine 200 with Order 2.
Two Document EntityType instances exist, one with EntityKey value 300 and the other with EntityKey value 301.
URI: The
scheme and Service Root
for this sample is http://host/service.svc.
Valid URIs that identify resources described using the conceptual schema definition language (CSDL) below are:
All Customers:
-
http://host/service.svc/Customers
Customer with key "ALFKI":
-
http://host/service.svc/Customers('ALFKI')
Orders for the Customer with key "ALFKI":
-
http://host/service.svc/Customers('ALFKI')/Orders
OrderLines for Order 1 associated with Customer ALFKI:
-
http://host/service.svc/Customers('ALFKI')/Orders(1)/OrderLines
The metadata document CSDL for the service:
-
http://host/service.svc/$metadata
The rules for constructing URIs which address aspects of an Entity Data Model are defined in Abstract Type System (section 2.2.2).
CSDL Document:
-
Note The conceptual schema definition language (CSDL) document below is shown within an <edmx:DataServices> element, as specified in [MC-EDMX].
-
<?xml version="1.0" encoding="utf-8" standalone="yes" ?> <edmx:Edmx Version="1.0" xmlns:edmx="http://schemas.microsoft.com/ado/2010/02/edmx" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"> <edmx:DataServices m:DataServiceVersion="3.0"> <Schema Namespace="SampleModel" xmlns="http://schemas.microsoft.com/ado/2006/04/edm"> <EntityContainer Name="SampleEntities" m:IsDefaultEntityContainer="true"> <EntitySet Name="Customers" EntityType="SampleModel.Customer" /> <EntitySet Name="Orders" EntityType="SampleModel.Order" /> <EntitySet Name="OrderLines" EntityType="SampleModel.OrderLine" /> <EntitySet Name="Employees" EntityType="SampleModel.Employee" /> <EntitySet Name="Documents" EntityType="SampleModel.Document" /> <EntitySet Name="Companies" EntityType="SampleModel.Company" /> <EntitySet Name="Photos" EntityType="SampleModel.Photo" /> <AssociationSet Name="Orders_Customers" Association="SampleModel.Orders_Customers"> <End Role="Customers" EntitySet="Customers" /> <End Role="Orders" EntitySet="Orders" /> </AssociationSet> <AssociationSet Name="OrderLines_Orders" Association="SampleModel.OrderLines_Orders"> <End Role="OrderLine" EntitySet="OrderLines" /> <End Role="Order" EntitySet="Orders" /> </AssociationSet> <!-- Service Operation --> <FunctionImport Name="CustomersByCity" EntitySet="Customers" ReturnType="Collection(SampleModel.Customer)" m:HttpMethod="GET"> <Parameter Name="city" Type="Edm.String" Mode="In" /> </FunctionImport> <!-- Functions --> <FunctionImport Name="GetRelatedCustomers" EntitySet="Customers" IsBindable="true" ReturnType="Collection(SampleModel.Customer)" IsSideEffecting="false"> <Parameter Name="company" Type="SampleModel.Company" Mode="In" /> </FunctionImport> <FunctionImport Name="TopTenCustomers" EntitySet="Customers" IsBindable="true" ReturnType="Collection(SampleModel.Customer)" IsSideEffecting="false"> <Parameter Name="customers" Type="Collection(SampleModel.Customer)" Mode="In" /> </FunctionImport> <FunctionImport Name="Best" EntitySet="Customers" IsBindable="true" ReturnType="SampleModel.Customer" IsSideEffecting="false" m:IsAlwaysBindable="false"> <Parameter Name="customers" Type="Collection(SampleModel.Customer)" Mode="In" /> </FunctionImport> <FunctionImport Name="TopTenOrders" EntitySet="Orders" IsBindable="true" ReturnType="Collection(SampleModel.Order)" IsSideEffecting="false"> <Parameter Name="customer" Type="SampleModel.Customer" Mode="In" /> </FunctionImport> <FunctionImport Name="TopTenCustomersInCity" EntitySet="Customers" IsBindable="true" ReturnType="Collection(SampleModel.Customer)" IsSideEffecting="false"> <Parameter Name="city" Type="Edm.String" Mode="In" /> </FunctionImport> <FunctionImport Name="HasOrderFor" IsBindable="true" ReturnType="Edm.Boolean" IsSideEffecting="false"> <Parameter Name="customer" Type="SampleModel.Customer" Mode="In" /> <Parameter Name="productType" Type="Edm.String" Mode="In" /> </FunctionImport> <!-- Actions --> <FunctionImport Name="CreateOrder" EntitySet="Orders" IsBindable="true" IsSideEffecting="true" m:IsAlwaysBindable="true"> <Parameter Name="customer" Type="SampleModel.Customer" Mode="In" /> <Parameter Name="quantity" Type="Edm.Int32" Mode="In" /> <Parameter Name="discountCode" Type="Edm.String" Mode="In" /> </FunctionImport> <FunctionImport Name="Audit" IsBindable="true" IsSideEffecting="true"> <Parameter Name="company" Type="SampleModel.Company" Mode="In" /> </FunctionImport> </EntityContainer> <EntityType Name="Order"> <Key> <PropertyRef Name="OrderID" /> </Key> <Property Name="OrderID" Type="Edm.Int32" Nullable="false" /> <Property Name="ShippedDate" Type="Edm.DateTime" Nullable="true" DateTimeKind="Unspecified" PreserveSeconds="true" /> <NavigationProperty Name="Customer" Relationship="SampleModel.Orders_Customers" FromRole="Order" ToRole="Customer" /> <NavigationProperty Name="OrderLines" Relationship="SampleModel.OrderLines_Orders" FromRole="Order" ToRole="OrderLine" /> </EntityType> <EntityType Name="OrderLine"> <Key> <PropertyRef Name="OrderLineID" /> </Key> <Property Name="OrderLineID" Type="Edm.Int32" Nullable="false" /> <Property Name="Quantity" Type="Edm.Int32" Nullable="false" /> <Property Name="UnitPrice" Type="Edm.Decimal" Nullable="false" /> <NavigationProperty Name="Order" Relationship="SampleModel.OrderLines_Orders" FromRole="OrderLine" ToRole="Order" /> </EntityType> <EntityType Name="Customer"> <Key> <PropertyRef Name="CustomerID" /> </Key> <Property Name="CustomerID" Type="Edm.String" Nullable="false" MaxLength="5" Unicode="true" FixedLength="true" /> <Property Name="CompanyName" Type="Edm.String" Nullable="false" MaxLength="40" Unicode="true" FixedLength="false" /> <Property Name="Address" Type="Sample.CAddress" Nullable="true" /> <Property Name="Version" Type="Edm.Binary" Nullable="true" MaxLength="8" FixedLength="true" ConcurrencyMode="Fixed" /> <Property Name="EmailAddresses" Type="Collection" Nullable="false"> <TypeRef Type ="Edm.String" Nullable="false"/> </Property> <Property Name="AlternateAddresses" Type="Collection" Nullable="false"> <TypeRef Type ="SampleModel.Address" Nullable="false"/> </Property> <NavigationProperty Name="Orders" Relationship="NorthwindModel.Orders_Customers" FromRole="Customer" ToRole="Order" /> </EntityType> <EntityType Name="VipCustomer" baseType="SampleModel.Customer" m:HasStream="true" > <Property Name="CreditPurchases" Type="SampleModel.CustomerCredit.Int32" Nullable="false"/> <Property Name="Logo" Type="Edm.Stream" /> <Property Name="CountriesOfOperation" Type="Collection" Nullable="false"> <TypeRef Type ="Edm.String" Nullable="false"/> </Property> <NavigationProperty Name="InHouseStaff" Relationship="NorthwindModel.Employee_VipCustomer" FromRole="VipCustomer" ToRole="Employee" /> </EntityType> <EntityType Name="GovernmentOrder" baseType="SampleModel.Order" > <Property Name="Country" Type="SampleModel.String" Nullable="false"/> </EntityType> <!—- The Employee EntityType has Web Customizable Feed property mappings that are supported only in OData 2.0 and OData 3.0 --> <EntityType Name="Employee" m:FC_KeepInContent="true" m:FC_TargetPath="Location" m:FC_SourcePath="Address/City" m:FC_NsUri="http://www.microsoft.com" m:FC_NsPrefix="emp"> <Key> <PropertyRef Name="EmployeeID" /> </Key> <Property Name="EmployeeID" Type="Edm.String" Nullable="false" MaxLength="5" Unicode="true" FixedLength="true" /> <Property Name="EmployeeName" Type="Edm.String" Nullable="false" MaxLength="40" Unicode="true" FixedLength="false" m:FC_KeepInContent="false" m:FC_TargetPath="SyndicationTitle"/> <Property Name="Address" Type="Sample.EAddress" Nullable="true" /> <Property Name="Version" Type="Edm.Binary" Nullable="true" MaxLength="8" FixedLength="true" ConcurrencyMode="Fixed" /> </EntityType> <EntityType Name="Document" m:HasStream="true"> <Key> <PropertyRef Name="DocumentID" /> </Key> <Property Name="DocumentID" Type="Edm.Int32" Nullable="false" /> <Property Name="Title" Type="Edm.String" Unicode="true" /> <Property Name="Author" Type="Edm.String" Unicode="true" /> </EntityType> <EntityType Name="Company"> <Key> <PropertyRef Name="CompanyID" /> </Key> <Property Name="CompanyID" Type="Edm.String" Nullable="false" MaxLength="5" Unicode="true" FixedLength="true" /> <Property Name="CompanySize" Type="Edm.String" Nullable="true"/> </EntityType> <ComplexType Name="Address" BaseType="SampleModel.EAddress"> <Property Name="Apartment" Type="Edm.Int"/> </ComplexType> <EntityType Name="Photo" m:HasStream="true"> <Key> <PropertyRef Name="ID" /> </Key> <Property Name="ID" Type="Edm.Int32" Nullable="false" /> <Property Name="Name" Type="Edm.String" Nullable="true" /> <Property Name="Thumbnail" Type="Edm.Stream" /> <Property Name="PrintReady" Type="Edm.Stream" /> </EntityType> <ComplexType Name="EAddress"> <Property Name="Street" Type="Edm.String" Unicode="true" /> <Property Name="City" Type="Edm.String" Unicode="true"/> </ComplexType> <ComplexType Name="CAddress"> <Property Name="Street" Type="Edm.String" Unicode="true" /> <Property Name="City" Type="Edm.String" Unicode="true"/> <Property Name="Location" Type="Edm.GeographyPoint" SRID="4326"/> </ComplexType> <ComplexType Name="CustomerCredit"> <Property Name="CreditLimit" Type="Edm.Int32" /> <Property Name="Balance" Type="Edm.Int32" /> </ComplexType> <Association Name="Orders_Customers"> <End Role="Customer" Type="SampleModel.Customer" Multiplicity="0..1" /> <End Role="Order" Type="SampleModel.Order" Multiplicity="*" /> </Association> <Association Name="OrderLines_Orders"> <End Role="Order" Type="SampleModel.OrderLine" Multiplicity="*" /> <End Role="OrderLine" Type="SampleModel.Order" Multiplicity="0..1" /> </Association> </Schema> </edmx:DataServices> </edmx:Edmx>