.NET Framework Class Library
ColumnAttribute Class

Associates a class with a column in a database table.

Namespace:  System.Data.Linq.Mapping
Assembly:  System.Data.Linq (in System.Data.Linq.dll)
Syntax

Visual Basic (Declaration)
<AttributeUsageAttribute(AttributeTargets.Property Or AttributeTargets.Field, AllowMultiple := False)> _
Public NotInheritable Class ColumnAttribute _
    Inherits DataAttribute
Visual Basic (Usage)
Dim instance As ColumnAttribute
C#
[AttributeUsageAttribute(AttributeTargets.Property|AttributeTargets.Field, AllowMultiple = false)]
public sealed class ColumnAttribute : DataAttribute
Visual C++
[AttributeUsageAttribute(AttributeTargets::Property|AttributeTargets::Field, AllowMultiple = false)]
public ref class ColumnAttribute sealed : public DataAttribute
JScript
public final class ColumnAttribute extends DataAttribute
Remarks

Use this attribute to designate a member of an entity class to represent a column in a database table. You can apply this attribute to any field or property that is public, private, or internal.

Only those entity class members identified as columns are persisted when LINQ to SQL saves changes to the database.

Use commas to separate multiple properties on the attribute.

Examples

Visual Basic
<Table(Name:="Employees")>  _
Public Class Employees
    Private _LastName As String
    ' …
    <Column(Storage:="_LastName", DbType:="NVarChar(20) NOT NULL", _
        CanBeNull:=false)> _
    Public Property LastName() As String
        Get
            Return Me._LastName
        End Get
        Set
            If ((Me._LastName = value) _
                = false) Then
                Me.OnPropertyChanging("LastName")
                Me._LastName = value
                Me.OnPropertyChanged("LastName")
            End If
        End Set
    End Property
End Class
C#
[Table(Name="Employees")]
public class Employees
{
    private string _LastName;    
    // …
    [Column(Storage="_LastName", DbType="NVarChar(20) NOT NULL", 
        CanBeNull=false)]
    public string LastName
    {
        get
        {
            return this._LastName;
        }
        set
        {
            if ((this._LastName != value))
            {
                this.OnPropertyChanging("LastName");
                this._LastName = value;
                this.OnPropertyChanged("LastName");
            }
        }
    }
}
Inheritance Hierarchy

System..::.Object
  System..::.Attribute
    System.Data.Linq.Mapping..::.DataAttribute
      System.Data.Linq.Mapping..::.ColumnAttribute
Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Platforms

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information

.NET Framework

Supported in: 3.5
See Also

Reference

Tags :


Page view tracker