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)

'Declaration
<AttributeUsageAttribute(AttributeTargets.Property)> _
Public NotInheritable Class DataObjectFieldAttribute
	Inherits Attribute
'Usage
Dim instance As DataObjectFieldAttribute

/** @attribute AttributeUsageAttribute(AttributeTargets.Property) */ 
public final class DataObjectFieldAttribute extends Attribute
AttributeUsageAttribute(AttributeTargets.Property) 
public final class DataObjectFieldAttribute extends Attribute
Not applicable.

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

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 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

ADD
Show:
© 2014 Microsoft