DataObjectMethodType 列舉
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
識別方法所執行之數據作業的類型,如套用至 方法的 DataObjectMethodAttribute 所指定。
public enum class DataObjectMethodType
public enum DataObjectMethodType
type DataObjectMethodType =
Public Enum DataObjectMethodType
- 繼承
欄位
| 名稱 | 值 | Description |
|---|---|---|
| Fill | 0 | 表示該方法用於填補 DataSet 物件的資料操作。 |
| Select | 1 | 表示某方法用於資料擷取操作。 |
| Update | 2 | 表示某方法用於資料操作以更新資料。 |
| Insert | 3 | 表示某方法用於插入資料的操作。 |
| Delete | 4 | 表示使用了刪除資料操作的方法。 |
範例
以下程式碼範例示範如何將 應用 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