DataObjectFieldAttribute Class
Provides metadata for a property representing a data field. This class cannot be inherited.
Assembly: System (in System.dll)
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 Sub New() End Sub 'New 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 'NorthwindEmployee
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.