DataObjectMethodAttribute 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
初始化 DataObjectMethodAttribute 類別的新執行個體。
多載
| 名稱 | Description |
|---|---|
| DataObjectMethodAttribute(DataObjectMethodType) |
初始化該類別的新實例 DataObjectMethodAttribute ,並識別該方法執行的資料操作類型。 |
| DataObjectMethodAttribute(DataObjectMethodType, Boolean) |
初始化該類別的新實例 DataObjectMethodAttribute ,識別該方法執行的資料操作類型,並判斷該方法是否為資料物件所暴露的預設資料方法。 |
DataObjectMethodAttribute(DataObjectMethodType)
初始化該類別的新實例 DataObjectMethodAttribute ,並識別該方法執行的資料操作類型。
public:
DataObjectMethodAttribute(System::ComponentModel::DataObjectMethodType methodType);
public DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType methodType);
new System.ComponentModel.DataObjectMethodAttribute : System.ComponentModel.DataObjectMethodType -> System.ComponentModel.DataObjectMethodAttribute
Public Sub New (methodType As DataObjectMethodType)
參數
- methodType
- DataObjectMethodType
DataObjectMethodType其中一個描述該方法執行的資料操作的值。
範例
以下程式碼範例示範如何將該屬性套用 DataObjectMethodAttribute 到公開暴露的方法,並識別它執行的資料操作類型,以及是否為該類型的預設資料方法。 在此範例中,該 NorthwindData 型別暴露了兩種資料方法:一種是檢索一組名為 GetAllEmployees的資料,另一種是刪除名為 DeleteEmployeeByID的資料。 屬性 DataObjectMethodAttribute 套用於兩個方法,該 GetAllEmployees 方法標記為 Select 資料操作的預設方法, DeleteEmployeeByID 該方法則標記為 Delete 資料操作的預設方法。
[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
備註
IsDefault這個屬性設定false為在你用這個DataObjectMethodAttribute(DataObjectMethodType)建構子建立DataObjectMethodAttribute物件時。
適用於
DataObjectMethodAttribute(DataObjectMethodType, Boolean)
初始化該類別的新實例 DataObjectMethodAttribute ,識別該方法執行的資料操作類型,並判斷該方法是否為資料物件所暴露的預設資料方法。
public:
DataObjectMethodAttribute(System::ComponentModel::DataObjectMethodType methodType, bool isDefault);
public DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType methodType, bool isDefault);
new System.ComponentModel.DataObjectMethodAttribute : System.ComponentModel.DataObjectMethodType * bool -> System.ComponentModel.DataObjectMethodAttribute
Public Sub New (methodType As DataObjectMethodType, isDefault As Boolean)
參數
- methodType
- DataObjectMethodType
DataObjectMethodType其中一個描述該方法執行的資料操作的值。
- isDefault
- Boolean
true表示屬性所應用的方法,是指定methodType資料物件的預設方法;否則,。 false
範例
以下程式碼範例示範如何將該屬性套用 DataObjectMethodAttribute 到公開暴露的方法,並識別它執行的資料操作類型,以及是否為該類型的預設資料方法。 在此範例中,該 NorthwindData 型別暴露了兩種資料方法:一種是檢索一組名為 GetAllEmployees的資料,另一種是刪除名為 DeleteEmployeeByID的資料。 屬性 DataObjectMethodAttribute 套用於兩個方法,該 GetAllEmployees 方法標記為 Select 資料操作的預設方法, DeleteEmployeeByID 該方法則標記為 Delete 資料操作的預設方法。
[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