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
Available since 2.0
Return to top
Show: