Using Element (CSDL)

Using Element (CSDL)

The Using element in conceptual schema definition language (CSDL) imports the contents of a conceptual model that exists in a different namespace. By setting the value of the Namespace attribute, you can refer to entity types, complex types, and association types that are defined in another conceptual model. More than one Using element can be a child of a Schema element.

Bb738545.note(en-us,VS.100).gifNote:
The Using element in CSDL does not function exactly like a using statement in a programming language. By importing a namespace with a using statement in a programming language, you do not affect objects in the original namespace. In CSDL, an imported namespace can contain an entity type that is derived from an entity type in the original namespace. This can affect entity sets declared in the original namespace. For more information about entity sets, see EntitySet Element.

The Using element can have the following child elements:

Applicable Attributes

The table below describes the attributes can be applied to the Using element.

Attribute Name Is Required Value

Namespace

Yes

The name of the imported namespace.

Alias

Yes

An identifier used in place of the namespace name. Although this attribute is required, it is not required that it be used in place of the namespace name to qualify object names.

Bb738545.note(en-us,VS.100).gifNote:
Any number of annotation attributes (custom XML attributes) may be applied to the Using element. However, custom attributes may not belong to any XML namespace that is reserved for CSDL. The fully-qualified names for any two custom attributes cannot be the same.

Example

The following example demonstrates the Using element being used to import a namespace that is defined elsewhere. Note that the namespace for the Schema element shown is BooksModel. The Address property on the Publisher EntityType is a complex type that is defined in the ExtendedBooksModel namespace (imported with the Using element).

  <Schema xmlns="http://schemas.microsoft.com/ado/2008/09/edm"
          xmlns:cg="http://schemas.microsoft.com/ado/2006/04/codegeneration"
          xmlns:store="http://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

Community Additions

ADD
Show:
© 2016 Microsoft