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

適用於

另請參閱