Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

DataObjectMethodAttribute Constructor (DataObjectMethodType)

Initializes a new instance of the DataObjectMethodAttribute class and identifies the type of data operation the method performs.

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

public DataObjectMethodAttribute(
	DataObjectMethodType methodType


Type: System.ComponentModel.DataObjectMethodType

One of the DataObjectMethodType values that describes the data operation the method performs.

The IsDefault property is set to false when you create a DataObjectMethodAttribute object using this DataObjectMethodAttribute(DataObjectMethodType) constructor.

The following code example demonstrates how you can apply the DataObjectMethodAttribute attribute to a publicly exposed method and identify the type of data operation it performs as well as whether it is the type's default data method. In this example the NorthwindData type exposes two data methods: one to retrieve a set of data named GetAllEmployees, and another to delete data named DeleteEmployeeByID. The DataObjectMethodAttribute attribute is applied to both methods, the GetAllEmployees method is marked as the default method for the Select data operation, and the DeleteEmployeeByID method is marked as the default method for the Delete data operation.

public class NorthwindData
  public NorthwindData() {}

  [DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
  public static IEnumerable GetAllEmployees()
    AccessDataSource ads = new AccessDataSource();
    ads.DataSourceMode = SqlDataSourceMode.DataReader;
    ads.DataFile = "~//App_Data//Northwind.mdb";
    ads.SelectCommand = "SELECT EmployeeID,FirstName,LastName FROM Employees";
    return ads.Select(DataSourceSelectArguments.Empty);

  // Delete the Employee by ID.
  [DataObjectMethodAttribute(DataObjectMethodType.Delete, true)]
  public void DeleteEmployeeByID(int employeeID)
    throw new Exception("The value passed to the delete method is "
                         + employeeID.ToString());

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

XNA Framework

Supported in: 3.0, 2.0, 1.0
© 2015 Microsoft