Export (0) Print
Expand All

DataObjectFieldAttribute Class

Provides metadata for a property representing a data field. This class cannot be inherited.

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

[AttributeUsageAttribute(AttributeTargets.Property)]
public sealed class DataObjectFieldAttribute : Attribute

Use the DataObjectFieldAttribute attribute to provide information about the schema of the underlying data. Design-time classes such as the ObjectDataSourceDesigner class use the DataObjectAttribute attribute to set properties at design-time based on the exposed schema.

You apply the DataObjectFieldAttribute attribute to members of the data item objects that are returned by the Select method of an object marked with the DataObjectAttribute attribute. In the following example, the NorthwindData class is marked with the DataObjectAttribute attribute, and returns an IEnumerable object containing NorthwindEmployee objects from the GetAllEmployees method. Fields in the NorthwindEmployee class are marked with the DataObjectFieldAttribute attribute to indicate they represent data fields in the underlying data source.

For more information about using attributes, see Extending Metadata Using Attributes.

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

System.Object
  System.Attribute
    System.ComponentModel.DataObjectFieldAttribute

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0

Community Additions

ADD
Show:
© 2014 Microsoft