DataObjectFieldAttribute 建構函式

定義

初始化 DataObjectFieldAttribute 類別的新執行個體。

多載

DataObjectFieldAttribute(Boolean)

初始化 DataObjectFieldAttribute 類別的新執行個體,並指出欄位是否為資料列的主索引鍵。

DataObjectFieldAttribute(Boolean, Boolean)

初始化 DataObjectFieldAttribute 類別的新執行個體,並指出欄位是否為資料列的主索引鍵,以及欄位是否為資料庫識別欄位。

DataObjectFieldAttribute(Boolean, Boolean, Boolean)

初始化 DataObjectFieldAttribute 類別的新執行個體,並指出欄位是否為資料列的主索引鍵、欄位是否為資料庫識別欄位,以及欄位是否可以為 null。

DataObjectFieldAttribute(Boolean, Boolean, Boolean, Int32)

初始化 DataObjectFieldAttribute 類別的新執行個體,並指出欄位是否為資料列的主索引鍵、它是否為資料庫識別欄位,以及它是否可以為 null 並設定欄位的長度。

DataObjectFieldAttribute(Boolean)

來源:
DataObjectFieldAttribute.cs
來源:
DataObjectFieldAttribute.cs
來源:
DataObjectFieldAttribute.cs

初始化 DataObjectFieldAttribute 類別的新執行個體,並指出欄位是否為資料列的主索引鍵。

public:
 DataObjectFieldAttribute(bool primaryKey);
public DataObjectFieldAttribute (bool primaryKey);
new System.ComponentModel.DataObjectFieldAttribute : bool -> System.ComponentModel.DataObjectFieldAttribute
Public Sub New (primaryKey As Boolean)

參數

primaryKey
Boolean

true 表示欄位在資料列的主索引鍵中,否則為 false

適用於

DataObjectFieldAttribute(Boolean, Boolean)

來源:
DataObjectFieldAttribute.cs
來源:
DataObjectFieldAttribute.cs
來源:
DataObjectFieldAttribute.cs

初始化 DataObjectFieldAttribute 類別的新執行個體,並指出欄位是否為資料列的主索引鍵,以及欄位是否為資料庫識別欄位。

public:
 DataObjectFieldAttribute(bool primaryKey, bool isIdentity);
public DataObjectFieldAttribute (bool primaryKey, bool isIdentity);
new System.ComponentModel.DataObjectFieldAttribute : bool * bool -> System.ComponentModel.DataObjectFieldAttribute
Public Sub New (primaryKey As Boolean, isIdentity As Boolean)

參數

primaryKey
Boolean

true 表示欄位在資料列的主索引鍵中,否則為 false

isIdentity
Boolean

true 表示欄位是可唯一識別資料列的識別 (Identity) 欄位,否則為 false

適用於

DataObjectFieldAttribute(Boolean, Boolean, Boolean)

來源:
DataObjectFieldAttribute.cs
來源:
DataObjectFieldAttribute.cs
來源:
DataObjectFieldAttribute.cs

初始化 DataObjectFieldAttribute 類別的新執行個體,並指出欄位是否為資料列的主索引鍵、欄位是否為資料庫識別欄位,以及欄位是否可以為 null。

public:
 DataObjectFieldAttribute(bool primaryKey, bool isIdentity, bool isNullable);
public DataObjectFieldAttribute (bool primaryKey, bool isIdentity, bool isNullable);
new System.ComponentModel.DataObjectFieldAttribute : bool * bool * bool -> System.ComponentModel.DataObjectFieldAttribute
Public Sub New (primaryKey As Boolean, isIdentity As Boolean, isNullable As Boolean)

參數

primaryKey
Boolean

true 表示欄位在資料列的主索引鍵中,否則為 false

isIdentity
Boolean

true 表示欄位是可唯一識別資料列的識別 (Identity) 欄位,否則為 false

isNullable
Boolean

true 表示欄位在資料存放區中可以為 null,否則為 false

範例

下列程式代碼範例示範如何將 套用 DataObjectFieldAttribute 至公開的屬性,以識別與 屬性相關聯的元數據。 在這裡範例中, NorthwindEmployee 此類型會公開三個資料屬性: EmployeeIDFirstNameLastName。 屬性 DataObjectFieldAttribute 會套用至這三個屬性;不過,只有 EmployeeID 屬性屬性表示它是數據列的主鍵。

public class NorthwindEmployee
{
  public NorthwindEmployee() { }

  private int _employeeID;
  [DataObjectFieldAttribute(true, true, false)]
  public int EmployeeID
  {
    get { return _employeeID; }
    set { _employeeID = value; }
  }

  private string _firstName = String.Empty;
  [DataObjectFieldAttribute(false, false, true)]
  public string FirstName
  {
    get { return _firstName; }
    set { _firstName = value; }
  }

  private string _lastName = String.Empty;
  [DataObjectFieldAttribute(false, false, true)]
  public string LastName
  {
    get { return _lastName; }
    set { _lastName = value; }
  }
}
Public Class NorthwindEmployee

  Public Sub New()
  End Sub

  Private _employeeID As Integer
  <DataObjectFieldAttribute(True, True, False)> _
  Public Property EmployeeID() As Integer
    Get
      Return _employeeID
    End Get
    Set(ByVal value As Integer)
      _employeeID = value
    End Set
  End Property

  Private _firstName As String = String.Empty
  <DataObjectFieldAttribute(False, False, False)> _
  Public Property FirstName() As String
    Get
      Return _firstName
    End Get
    Set(ByVal value As String)
      _firstName = value
    End Set
  End Property

  Private _lastName As String = String.Empty
  <DataObjectFieldAttribute(False, False, False)> _
  Public Property LastName() As String
    Get
      Return _lastName
    End Get
    Set(ByVal value As String)
      _lastName = value
    End Set
  End Property

End Class

適用於

DataObjectFieldAttribute(Boolean, Boolean, Boolean, Int32)

來源:
DataObjectFieldAttribute.cs
來源:
DataObjectFieldAttribute.cs
來源:
DataObjectFieldAttribute.cs

初始化 DataObjectFieldAttribute 類別的新執行個體,並指出欄位是否為資料列的主索引鍵、它是否為資料庫識別欄位,以及它是否可以為 null 並設定欄位的長度。

public:
 DataObjectFieldAttribute(bool primaryKey, bool isIdentity, bool isNullable, int length);
public DataObjectFieldAttribute (bool primaryKey, bool isIdentity, bool isNullable, int length);
new System.ComponentModel.DataObjectFieldAttribute : bool * bool * bool * int -> System.ComponentModel.DataObjectFieldAttribute
Public Sub New (primaryKey As Boolean, isIdentity As Boolean, isNullable As Boolean, length As Integer)

參數

primaryKey
Boolean

true 表示欄位在資料列的主索引鍵中,否則為 false

isIdentity
Boolean

true 表示欄位是可唯一識別資料列的識別 (Identity) 欄位,否則為 false

isNullable
Boolean

true 表示欄位在資料存放區中可以為 null,否則為 false

length
Int32

欄位的長度,以位元組為單位。

適用於