Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2008
Visual Studio
Accessing Data
ADO.NET
Feature Reference
Entity Data Model
EDM Specifications
 Entity Containers (EDM)

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
Entity Containers (EDM)

In the Entity Data Model (EDM) an EntityContainer is a logical grouping of entity sets and association sets. Because the programming model is built from the conceptual schema definition language (CSDL) schema, an EntityContainer is the specification for a namespace in the object model being defined. In the store schema definition language (SSDL) schema, the EntityContainer identifies the storage container that persists data for applications built on the model. This can be a database in a relational database management system (RDBMS) or some other technology.

The EntityContainer controls the scope of entities and relationships. All types in the EDM are defined in scope of an EntityContainer namespace. Instances of EntitySet and AssociationSet are created in scope of an EntityContainer. Similarly, instances of an EntityType or an Association are created in scope of an EntitySet or an AssociationSet.

In the XML hierarchy, the EntityContainer element is separate from the Schema element even though the EntityContainer is defined in a schema. This is important in mapping the EntityContainer to storage. In the mapping file, the fully qualified name of the EntityContainer does not include the schema namespace name.

An EntityContainer is derived from the basic EntityContainer construct provided by the EDM. The EntityContainer specifies types derived from EntitySet and AssociationSet.

An EntitySet defined in an EntityContainer can contain an EntityType defined in a separate EntityContainer.

An AssociationSet can not reference an EntitySet defined in a separate EntityContainer.

The following example shows the declarations of two entity types and an association type, and then the declaration of an EntityContainer with two entity sets and an association set.

The following schema contains the entity declarations:

<?xml version="1.0" encoding="utf-8"?>
<Schema xmlns:cg="http://schemas.microsoft.com/ado/2006/04/codegeneration"
    xmlns:edm="http://schemas.microsoft.com/ado/2006/04/edm"
    xmlns="http://schemas.microsoft.com/ado/2006/04/edm"
    Namespace="MyCompany.EntityTypes" Alias="Self">

    <EntityType Name="Order">
        <Key>
            <PropertyRef Name="OrderId" />
        </Key>
        <Property Name="OrderId" Type="String" />
        <!--Other Properties-->
    </EntityType>

    <EntityType Name="Customer">
        <Key>
            <PropertyRef Name="CustomerId" />
        </Key>
        <Property Name="CustomerId" Type="String" />
        <!--Other Properties-->
    </EntityType>

</Schema>

The following schema contains the association declarations:

<?xml version="1.0" encoding="utf-8"?>
<Schema xmlns:cg="http://schemas.microsoft.com/ado/2006/04/codegeneration"
    xmlns:edm="http://schemas.microsoft.com/ado/2006/04/edm"
    xmlns="http://schemas.microsoft.com/ado/2006/04/edm"
    Namespace="MyCompany.RelationshipTypes">

    <Using Namespace="MyCompany.EntityTypes" Alias="basicTypes"/>

    <Association Name="CustomerOrder">
        <End Type="basicTypes.Customer" Multiplicity="1" />
        <End Type="basicTypes.Order" Multiplicity="*" />
    </Association>
</Schema>

The following schema contains the entity container declaration:

<?xml version="1.0" encoding="utf-8"?>
<Schema xmlns:cg="http://schemas.microsoft.com/ado/2006/04/codegeneration"
    xmlns:edm="http://schemas.microsoft.com/ado/2006/04/edm"
    xmlns="http://schemas.microsoft.com/ado/2006/04/edm"
    Namespace="MyCompany.ContainerType">

    <EntityContainer name="ContainerOne">
        <Using Namespace="MyCompany.EntityTypes" Alias="basicTypes"/>
        <Using Namespace="MyCompany.RelationshipTypes" Alias="relnTypes"/>

        <EntitySet Name="CustomerSet" EntityType="basicTypes.Customer"/>
        <EntitySet Name="OrderSet" EntityType="basicTypes.Order"/>

        <AssociationSet Name="CustomerOrderSet" Association="relnTypes.CustomerOrder">
            <End EntitySet="CustomerSet" Role="Orders"/>
            <End EntitySet="OrderSet" Role="OrderedBy"/>
        </AssociationSet>
    </EntityContainer>
</Schema>

See Also

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
A mistake in example      FLUID   |   Edit   |   Show History

<EntityContainer name="ContainerOne">
<Using Namespace="MyCompany.EntityTypes" Alias="basicTypes"/>
<Using Namespace="MyCompany.RelationshipTypes" Alias="relnTypes"/>

<EntitySet Name="CustomerSet" EntityType="basicTypes.Customer"/>
<EntitySet Name="OrderSet" EntityType="basicTypes.Order"/>

<AssociationSet Name="CustomerOrderSet" Association="relnTypes.CustomerOrder">
<End EntitySet="CustomerSet" Role="Orders"/>
<End EntitySet="OrderSet" Role="OrderedBy"/>
</AssociationSet>
</EntityContainer>


A Using element is inside the EntityContainer, but accoring to CSDLSChema.xsd EntityContainer doesn't contain Using elements. Using is a part of Schema element.


<xs:elementname="Schema"type="edm:TSchema" />

<xs:complexTypename="TSchema">

<xs:sequence>

<xs:groupref="edm:GSchemaBodyElements"minOccurs="0"maxOccurs="unbounded" />

......

</xs:complexType>

<xs:groupname="GSchemaBodyElements">

<xs:choice>

<xs:elementname="Using"type="edm:TUsing"minOccurs="0"maxOccurs="unbounded" />

......

<xs:elementref="edm:EntityContainer"minOccurs="1"maxOccurs="1" />

</xs:choice>

</xs:group>

Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker