Partilhar via


Entity Data Model: Namespaces

A namespace in the Entity Data Model (EDM) is an abstract container for entity types, complex types, and associations. Namespaces in the EDM are similar to namespaces in a programming language: they provide context for the objects that they contain and they provide a way to disambiguate objects that have the same name (but are contained in different namespaces).

Example

The ADO.NET Entity Framework uses a domain-specific language (DSL) called conceptual schema definition language (CSDL) to define conceptual models. The following CSDL code uses a namespace to identify a type that is defined in a different conceptual model. The example defines an entity type (Publisher) that has a complex type property (Address) that is imported from the ExtendedBooksModel namespace. Note that the Using element indicates that a namespace has been imported. Also note that the type of the Address property is defined by using its fully qualified name (ExtendedBooksModel.Address), indicating that this type is defined in the ExtendedBooksModel namespace.

      <Schema xmlns="https://schemas.microsoft.com/ado/2008/09/edm"
              xmlns:cg="https://schemas.microsoft.com/ado/2006/04/codegeneration"
              xmlns:store="https://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator"
              Namespace="BooksModel" Alias="Self">

        <Using Namespace="BooksModel.Extended" Alias="BMExt" />

    <EntityContainer Name="BooksContainer" >
          <EntitySet Name="Publishers" EntityType="BooksModel.Publisher" />
        </EntityContainer>

    <EntityType Name="Publisher">
          <Key>
            <PropertyRef Name="Id" />
          </Key>
          <Property Type="Int32" Name="Id" Nullable="false" />
          <Property Type="String" Name="Name" Nullable="false" />
          <Property Type="BMExt.Address" Name="Address" Nullable="false" />
        </EntityType>

    </Schema>

See Also

Concepts

Entity Data Model Key Concepts

Entity Data Model