DataObjectFieldAttribute 類別

定義

為表示資料欄位的屬性,提供中繼資料。 此類別無法獲得繼承。

public ref class DataObjectFieldAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Property)]
public sealed class DataObjectFieldAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Property)>]
type DataObjectFieldAttribute = class
    inherit Attribute
Public NotInheritable Class DataObjectFieldAttribute
Inherits Attribute
繼承
DataObjectFieldAttribute
屬性

範例

下列程式代碼範例示範如何將 套用 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使用屬性來提供基礎數據架構的相關信息。 類別之類的 ObjectDataSourceDesigner 設計時間類別會 DataObjectAttribute 使用 屬性,根據公開的架構在設計時間設定屬性。

您可以將 屬性套用 DataObjectFieldAttribute 至以 屬性標示 DataObjectAttribute 之物件的 Select 方法所傳回之數據項對象的成員。 在下列範例中,類別 NorthwindData 會以 DataObjectAttribute 屬性標記,並從方法傳回 IEnumerable 包含 NorthwindEmployee 對象的物件 GetAllEmployees 。 類別中的 NorthwindEmployee 欄位會以 DataObjectFieldAttribute 屬性標示,以指出它們代表基礎數據源中的數據欄位。

如需使用屬性的詳細資訊,請參閱 屬性

建構函式

DataObjectFieldAttribute(Boolean)

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

DataObjectFieldAttribute(Boolean, Boolean)

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

DataObjectFieldAttribute(Boolean, Boolean, Boolean)

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

DataObjectFieldAttribute(Boolean, Boolean, Boolean, Int32)

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

屬性

IsIdentity

取得值,指出屬性是否表示基礎資料中的識別欄位。

IsNullable

取得值,指出屬性是否表示基礎資料存放區中的可為 null 欄位。

Length

取得屬性的長度,以位元組為單位。

PrimaryKey

取得值,指出屬性是否位於基礎資料中的主索引鍵。

TypeId

在衍生類別中實作時,取得這個 Attribute 的唯一識別碼。

(繼承來源 Attribute)

方法

Equals(Object)

傳回值,該值表示這個執行個體是否和指定的物件相等。

GetHashCode()

傳回這個執行個體的雜湊碼。

GetType()

取得目前執行個體的 Type

(繼承來源 Object)
IsDefaultAttribute()

在衍生類別中覆寫時,表示這個執行個體的值是衍生類別的預設值。

(繼承來源 Attribute)
Match(Object)

在衍生類別中覆寫時,會傳回值,表示這個執行個體是否等於指定物件。

(繼承來源 Attribute)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

明確介面實作

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。

(繼承來源 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

擷取物件的類型資訊,可以用來取得介面的類型資訊。

(繼承來源 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

擷取物件提供的類型資訊介面數目 (0 或 1)。

(繼承來源 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供物件所公開的屬性和方法的存取權。

(繼承來源 Attribute)

適用於