Condividi tramite


ContentType (SPMetal)

Applies to: SharePoint Foundation 2010

Specifies that a content type should be included in code generation and modifies which columns in the content type are included in code generation.

Web (SPMetal)
  ContentType (SPMetal)

<ContentType Name="Contact" Class="Contact"> ... </ContentType>

Complex

Attributes and Elements

The following sections describe attributes, child elements, and parent elements.

Attributes

Attribute

Description

Name (required)

The name of the content type in SharePoint Foundation.

Member (optional)

The name SPMetal should give to the property that it generates to represent the list.

AccessModifier (optional)

Specifies whether the class is public or internal.

AccessModifier Attribute Possible Values:

Value

Description

Internal

The class will be internal (Friend in Visual Basic).

Public

DEFAULT: The class will be public (Public in Visual Basic).

Child Elements

Element

Description

Column

Includes a column (field) in code generation.

ExcludeColumn

Excludes a column in code generation.

ExcludeOtherColumns

Excludes from code generation all columns not explicitly included with a Column element.

IncludeHiddenColumns

Includes hidden columns in code generation.

Parent Elements

Element

Description

Web (SPMetal)

Specifies the name and access level (public or internal) of the class (derived from DataContext) that SPMetal generates.

List (SPMetal)

Includes a list in code generation and modifies how code is generated for list-scoped content types.

Remarks

A ContentType element cannot have both a Column element and an ExcludeColumn element that name the same column. An ExcludeColumn element that names a hidden column may not be present in the same ContentType element that has an IncludeHiddenColumns element. Finally, a ContentType element cannot have both an ExcludeOtherColumns element and an IncludeHiddenColumns element.

Example

The following is an example of a ContentType element in use. If this was a hidden content type, the presence of the element would ensure that it was included in code generation. The Class attribute in the element ensures that the class is named "Contract" instead of the default name "ContractsItem". A list-scoped ContentType element ensures that the class that represents the content type of the list is named "TeamMember" instead of "TeamMembersItem".

<?xml version="1.0" encoding="utf-8"?>
<Web AccessModifier="Internal" xmlns="https://schemas.microsoft.com/SharePoint/2009/spmetal">
  <ContentType Name="Contact" Class="Contact">
    <Column Name="ContId" Member="ContactId" />
    <Column Name="ContactName" Member="ContactName1" />
    <Column Name="Category" Member="Cat" Type="String"/>
    <ExcludeColumn Name="HomeTelephone" />
  </ContentType>
  <ExcludeContentType Name="Order"/>
  <List Name="Team Members">
    <ContentType Name="Item" Class="TeamMember" />
  </List>
</Web>

See Also

Concepts

SPMetal Default Code Generation Rules

Overriding SPMetal Defaults by Using a Parameters XML File