DataObjectFieldAttribute 构造函数

定义

初始化 DataObjectFieldAttribute 类的新实例。

重载

DataObjectFieldAttribute(Boolean)

初始化 DataObjectFieldAttribute 类的新实例,并指示该字段是否是数据行的主键。

DataObjectFieldAttribute(Boolean, Boolean)

初始化 DataObjectFieldAttribute 类的新实例,并指示该字段是否是数据行的主键,以及该字段是否是数据库标识字段。

DataObjectFieldAttribute(Boolean, Boolean, Boolean)

初始化 DataObjectFieldAttribute 类的新实例,并指示该字段是否是数据行的主键,该字段是否是数据库标识字段,以及该字段是否可以为空。

DataObjectFieldAttribute(Boolean, Boolean, Boolean, Int32)

初始化 DataObjectFieldAttribute 类的新实例,指示该字段是否是数据行的主键,该字段是否是数据库标识字段以及该字段是否可以为空,并设置该字段的长度。

DataObjectFieldAttribute(Boolean)

Source:
DataObjectFieldAttribute.cs
Source:
DataObjectFieldAttribute.cs
Source:
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)

Source:
DataObjectFieldAttribute.cs
Source:
DataObjectFieldAttribute.cs
Source:
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 指示该字段是唯一标识数据行的标识字段;否则为 false

适用于

DataObjectFieldAttribute(Boolean, Boolean, Boolean)

Source:
DataObjectFieldAttribute.cs
Source:
DataObjectFieldAttribute.cs
Source:
DataObjectFieldAttribute.cs

初始化 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 类型公开三个数据属性: 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)

Source:
DataObjectFieldAttribute.cs
Source:
DataObjectFieldAttribute.cs
Source:
DataObjectFieldAttribute.cs

初始化 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

字段的长度(以字节为单位)。

适用于