DataObjectMethodAttribute 建構函式

定義

初始化 DataObjectMethodAttribute 類別的新執行個體。

多載

DataObjectMethodAttribute(DataObjectMethodType)

初始化 DataObjectMethodAttribute 類別的新執行個體,並識別方法所執行的資料作業類型。

DataObjectMethodAttribute(DataObjectMethodType, Boolean)

初始化 DataObjectMethodAttribute 類別的新執行個體、識別方法所執行的資料作業類型,並識別方法是否為資料物件所公開的預設資料方法。

DataObjectMethodAttribute(DataObjectMethodType)

來源:
DataObjectMethodAttribute.cs
來源:
DataObjectMethodAttribute.cs
來源:
DataObjectMethodAttribute.cs

初始化 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

備註

當您使用此DataObjectMethodAttribute(DataObjectMethodType)建構函式建立 物件時,屬性IsDefault會設定falseDataObjectMethodAttribute

適用於

DataObjectMethodAttribute(DataObjectMethodType, Boolean)

來源:
DataObjectMethodAttribute.cs
來源:
DataObjectMethodAttribute.cs
來源:
DataObjectMethodAttribute.cs

初始化 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

適用於