DataObjectMethodType 列舉

定義

識別方法所執行的資料作業類型,由套用至方法的 DataObjectMethodAttribute 所指定。

C#
public enum DataObjectMethodType
繼承
DataObjectMethodType

欄位

名稱 Description
Delete 4

表示方法用於刪除資料的資料作業。

Fill 0

表示方法用於填滿 DataSet 物件的資料作業。

Insert 3

表示方法用於插入資料的資料作業。

Select 1

表示方法用於擷取資料的資料作業。

Update 2

表示方法用於更新資料的資料作業。

範例

下列程式代碼範例示範如何將 套用 DataObjectMethodAttribute 至公開的方法,並識別其執行的數據作業類型,以及它是否為類型的默認數據方法。 在此範例中, NorthwindEmployee 此類型會公開兩個不同的數據方法:一個用來擷取一組名為 GetAllEmployees的數據,另一個用來刪除名為 DeleteEmployeeByID的數據。 會 DataObjectMethodAttribute 套用至這兩種方法。

C#
[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());
  }
}

適用於

產品 版本
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

另請參閱