DataObjectFieldAttribute 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
初始化 DataObjectFieldAttribute 類別的新執行個體。
多載
| 名稱 | Description |
|---|---|
| DataObjectFieldAttribute(Boolean) |
初始化該類別的新實例 DataObjectFieldAttribute ,並指示該欄位是否為資料列的主鍵。 |
| DataObjectFieldAttribute(Boolean, Boolean) |
初始化該 DataObjectFieldAttribute 類別的新實例,並指示該欄位是否為資料列的主鍵,以及該欄位是否為資料庫識別欄位。 |
| DataObjectFieldAttribute(Boolean, Boolean, Boolean) |
初始化該類別的新實例 DataObjectFieldAttribute ,並指示該欄位是否為資料列的主鍵、該欄位是否為資料庫身份欄位,以及該欄位是否可以為空。 |
| DataObjectFieldAttribute(Boolean, Boolean, Boolean, Int32) |
初始化該類別的新實例 DataObjectFieldAttribute ,並指示該欄位是否為資料列的主鍵、是否為資料庫身份欄位,以及是否可為空,並設定欄位長度。 |
DataObjectFieldAttribute(Boolean)
初始化該類別的新實例 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 類別的新實例,並指示該欄位是否為資料列的主鍵,以及該欄位是否為資料庫識別欄位。
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表示該欄位是一個唯一識別資料列的單位欄位;否則,。 false
適用於
DataObjectFieldAttribute(Boolean, Boolean, Boolean)
初始化該類別的新實例 DataObjectFieldAttribute ,並指示該欄位是否為資料列的主鍵、該欄位是否為資料庫身份欄位,以及該欄位是否可以為空。
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表示該欄位是一個唯一識別資料列的單位欄位;否則,。 false
- isNullable
- Boolean
true用以表示欄位在資料儲存中可以為空;否則,。 false
範例
以下程式碼範例示範如何將 應用於 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(Boolean, Boolean, Boolean, Int32)
初始化該類別的新實例 DataObjectFieldAttribute ,並指示該欄位是否為資料列的主鍵、是否為資料庫身份欄位,以及是否可為空,並設定欄位長度。
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表示該欄位是一個唯一識別資料列的單位欄位;否則,。 false
- isNullable
- Boolean
true用以表示欄位在資料儲存中可以為空;否則,。 false
- length
- Int32
欄位長度以位元組為單位。