Column (SPMetal)

Applies to: SharePoint Foundation 2010

Specifies that a column (field) is included in code generation.

Web (SPMetal)
  ContentType (SPMetal)
    Column (SPMetal)

<Column Name="Category" Member="Cat" Type="String"/>

Complex

Attributes and Elements

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

Attributes

Attribute

Description

Name (required)

The internalMicrosoft SharePoint Foundation name of the column (field).

Member (optional)

The name SPMetal gives to the property that it generates to represent the column.

Type (optional)

Used only for Choice and MultiChoice columns that do not allow 'Fill-in' choices. If present and set to "String", forces SPMetal to generate a class of String constants to represent the possible choices rather than an enum class. For more information about how LINQ to SharePoint maps Choice and MultiChoice fields to .NET 3.5 data types, see Type Mapping: From LINQ to SharePoint Provider to .NET.

Possible Values of Type Attribute

Value

Description

String

Tells SPMetal to generate a class of String constants to represent the possible choices rather than an enum class.

Child Elements

None.

Parent Elements

Element

Description

ContentType (SPMetal)

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

Remarks

A ContentType element cannot have both a Column element and an ExcludeColumn element that name the same column.

Example

The following shows some Column elements in use. Each of them ensures that the column it names is included in code generation even if it is a hidden column. The Member attribute in each case gives the property that represents the column a name that differs from the internal SharePoint Foundation column name. One Column element represents the Choice column "Category". It uses the Type parameter to force SPMetal to generate a set of String constants to represent the possible choices rather than an enum.

<?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" Type="TeamMember">
    <ContentType Name="Item" Class="TeamMember" />
  </List>
</Web>

See Also

Concepts

SPMetal Default Code Generation Rules

Overriding SPMetal Defaults by Using a Parameters XML File

Type Mapping: From LINQ to SharePoint Provider to .NET