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別暴露三個資料屬性:EmployeeID、、 FirstNameLastName和 。 屬性 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 ,表示它們代表底層資料來源中的資料欄位。

欲了解更多屬性的使用資訊,請參閱屬性。

建構函式

名稱 Description
DataObjectFieldAttribute(Boolean, Boolean, Boolean, Int32)

初始化該類別的新實例 DataObjectFieldAttribute ,並指示該欄位是否為資料列的主鍵、是否為資料庫身份欄位,以及是否可為空,並設定欄位長度。

DataObjectFieldAttribute(Boolean, Boolean, Boolean)

初始化該類別的新實例 DataObjectFieldAttribute ,並指示該欄位是否為資料列的主鍵、該欄位是否為資料庫身份欄位,以及該欄位是否可以為空。

DataObjectFieldAttribute(Boolean, Boolean)

初始化該 DataObjectFieldAttribute 類別的新實例,並指示該欄位是否為資料列的主鍵,以及該欄位是否為資料庫識別欄位。

DataObjectFieldAttribute(Boolean)

初始化該類別的新實例 DataObjectFieldAttribute ,並指示該欄位是否為資料列的主鍵。

屬性

名稱 Description
IsIdentity

取得一個值,表示某屬性是否代表底層資料中的身份欄位。

IsNullable

會取得一個值,表示某屬性是否代表底層資料庫中可為空的欄位。

Length

以位元組表示屬性的長度。

PrimaryKey

取得一個值,表示某屬性是否在底層資料的主鍵中。

TypeId

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

(繼承來源 Attribute)

方法

名稱 Description
Equals(Object)

傳回值,指出這個實例是否等於指定的物件。

GetHashCode()

傳回這個實例的哈希碼。

GetType()

取得目前實例的 Type

(繼承來源 Object)
IsDefaultAttribute()

在衍生類別中覆寫時,指出這個實例的值是否為衍生類別的預設值。

(繼承來源 Attribute)
Match(Object)

在衍生類別中覆寫時,傳回值,指出這個實例是否等於指定的物件。

(繼承來源 Attribute)
MemberwiseClone()

建立目前 Object的淺層複本。

(繼承來源 Object)
ToString()

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

(繼承來源 Object)

明確介面實作

名稱 Description
_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)

適用於