DataObjectMethodType 枚举

定义

根据应用于某方法的 DataObjectMethodAttribute 的指定,标识该方法所执行的数据操作类型。

public enum class DataObjectMethodType
public enum DataObjectMethodType
type DataObjectMethodType = 
Public Enum DataObjectMethodType
继承
DataObjectMethodType

字段

Delete 4

指示某一方法是否用于删除数据的数据操作。

Fill 0

指示某一方法是否用于填充 DataSet 对象的数据操作。

Insert 3

指示某一方法是否用于插入数据的数据操作。

Select 1

指示某一方法是否用于检索数据的数据操作。

Update 2

指示某一方法是否用于更新数据的数据操作。

示例

下面的代码示例演示如何将 应用于 DataObjectMethodAttribute 公开的方法,并标识它执行的数据操作的类型以及它是否为类型的默认数据方法。 在此示例中, NorthwindEmployee 类型公开两种不同的数据方法:一种用于检索名为 GetAllEmployees的一组数据,另一种用于删除名为 的数据 DeleteEmployeeByID。 将 DataObjectMethodAttribute 应用于这两种方法。

[DataObjectAttribute]
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());
  }
}
<DataObjectAttribute()> _
Public Class NorthwindData

  <DataObjectMethodAttribute(DataObjectMethodType.Select, True)> _
  Public Shared Function GetAllEmployees() As IEnumerable
    Dim ads As 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)
  End Function 'GetAllEmployees

  ' Delete the Employee by ID.
  <DataObjectMethodAttribute(DataObjectMethodType.Delete, True)> _
  Public Sub DeleteEmployeeByID(ByVal employeeID As Integer)
    Throw New Exception("The value passed to the delete method is " + employeeID.ToString())
  End Sub

End Class

适用于

另请参阅