This documentation is archived and is not being maintained.

DataObjectFieldAttribute Constructor (Boolean, Boolean, Boolean)

Initializes a new instance of the DataObjectFieldAttribute class and indicates whether the field is the primary key for the data row, whether the field is a database identity field, and whether the field can be null.

Namespace:  System.ComponentModel
Assembly:  System (in System.dll)

public DataObjectFieldAttribute(
	bool primaryKey,
	bool isIdentity,
	bool isNullable
)

Parameters

primaryKey
Type: System.Boolean
true to indicate that the field is in the primary key of the data row; otherwise, false.
isIdentity
Type: System.Boolean
true to indicate that the field is an identity field that uniquely identifies the data row; otherwise, false.
isNullable
Type: System.Boolean
true to indicate that the field can be null in the data store; otherwise, false.

The following code example demonstrates how you can apply the DataObjectFieldAttribute to a publicly exposed property to identify metadata associated with the property. In this example the NorthwindEmployee type exposes three data properties: EmployeeID, FirstName, and LastName. The DataObjectFieldAttribute attribute is applied to all three properties; however, only the EmployeeID property attribute indicates it is the primary key for the data row.


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; }
  }
}


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Show: