DataObjectMethodType 列舉

定義

識別方法所執行的資料作業類型,由套用至方法的 DataObjectMethodAttribute 所指定。Identifies the type of data operation performed by a method, as specified by the DataObjectMethodAttribute applied to the method.

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

欄位

Delete 4

表示方法用於刪除資料的資料作業。Indicates that a method is used for a data operation that deletes data.

Fill 0

表示方法用於填滿 DataSet 物件的資料作業。Indicates that a method is used for a data operation that fills a DataSet object.

Insert 3

表示方法用於插入資料的資料作業。Indicates that a method is used for a data operation that inserts data.

Select 1

表示方法用於擷取資料的資料作業。Indicates that a method is used for a data operation that retrieves data.

Update 2

表示方法用於更新資料的資料作業。Indicates that a method is used for a data operation that updates data.

範例

下列程式碼範例示範如何將DataObjectMethodAttribute套用至公開公開的方法, 並識別它所執行的資料作業類型, 以及它是否為類型的預設資料方法。The following code example demonstrates how you can apply the DataObjectMethodAttribute 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. 在此範例中NorthwindEmployee , 型別會公開兩個不同的資料方法: 一個用來GetAllEmployees抓取一組名為的資料DeleteEmployeeByID, 另一個則用來刪除名為的資料。In this example the NorthwindEmployee type exposes two different data methods: one to retrieve a set of data named GetAllEmployees, and one to delete data named DeleteEmployeeByID. DataObjectMethodAttribute適用于這兩種方法。The DataObjectMethodAttribute is applied to both methods.

[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

適用於

另請參閱