请单击以进行评分并提供反馈

  开启低带宽视图
.NET Framework 类库
ColumnAttribute 类

更新:2007 年 11 月

将类与数据库表中的列相关联。

命名空间:  System.Data.Linq.Mapping
程序集:  System.Data.Linq(在 System.Data.Linq.dll 中)

Visual Basic(声明)
<AttributeUsageAttribute(AttributeTargets.Property Or AttributeTargets.Field, AllowMultiple := False)> _
Public NotInheritable Class ColumnAttribute _
    Inherits DataAttribute
Visual Basic (用法)
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
J#
/** @attribute AttributeUsageAttribute(AttributeTargets.Property|AttributeTargets.Field, AllowMultiple = false) */
public final class ColumnAttribute extends DataAttribute
JScript
public final class ColumnAttribute extends DataAttribute

使用此属性可指定实体类的某个成员表示数据库表中的列。可以将此属性应用于 publicprivateinternal 类型的任何字段或属性。

当 LINQ to SQL 保存对数据库所做的更改时,只有那些标识为列的实体类成员是持久的。

使用逗号分隔属性 (Attribute) 的多个属性 (Property)。

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");
            }
        }
    }
}
System..::.Object
  System..::.Attribute
    System.Data.Linq.Mapping..::.DataAttribute
      System.Data.Linq.Mapping..::.ColumnAttribute
此类型的任何公共 static(在 Visual Basic 中为 Shared) 成员都是线程安全的。但不保证所有实例成员都是线程安全的。

Windows Vista, Windows XP SP2, Windows Server 2003

.NET Framework 和 .NET Compact Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求

.NET Framework

受以下版本支持:3.5
社区内容   什么是社区内容?
添加新内容 RSS  批注
Processing
© 2009 Microsoft Corporation 版权所有。 保留所有权利  |  商标  |  隐私权声明
Page view tracker