次の方法で共有


DataObjectMethodAttribute コンストラクター

定義

DataObjectMethodAttribute クラスの新しいインスタンスを初期化します。

オーバーロード

名前 説明
DataObjectMethodAttribute(DataObjectMethodType)

DataObjectMethodAttribute クラスの新しいインスタンスを初期化し、メソッドが実行するデータ操作の種類を識別します。

DataObjectMethodAttribute(DataObjectMethodType, Boolean)

DataObjectMethodAttribute クラスの新しいインスタンスを初期化し、メソッドが実行するデータ操作の種類を識別し、メソッドがデータ オブジェクトが公開する既定のデータ メソッドであるかどうかを識別します。

DataObjectMethodAttribute(DataObjectMethodType)

ソース:
DataObjectMethodAttribute.cs
ソース:
DataObjectMethodAttribute.cs
ソース:
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 値の 1 つ。

次のコード例では、パブリックに公開されているメソッドに DataObjectMethodAttribute 属性を適用し、実行するデータ操作の種類と、それが型の既定のデータ メソッドであるかどうかを識別する方法を示します。 この例では、 NorthwindData 型は 2 つのデータ メソッドを公開しています。1 つは GetAllEmployees という名前のデータ セットを取得し、もう 1 つは DeleteEmployeeByID という名前のデータを削除するメソッドです。 DataObjectMethodAttribute属性は両方のメソッドに適用され、GetAllEmployees メソッドはデータの選択操作の既定のメソッドとしてマークされ、DeleteEmployeeByID メソッドはデータの削除操作の既定のメソッドとしてマークされます。

[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 プロパティは、このDataObjectMethodAttribute(DataObjectMethodType)コンストラクターを使用してDataObjectMethodAttribute オブジェクトを作成するときにfalseに設定されます。

適用対象

DataObjectMethodAttribute(DataObjectMethodType, Boolean)

ソース:
DataObjectMethodAttribute.cs
ソース:
DataObjectMethodAttribute.cs
ソース:
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 値の 1 つ。

isDefault
Boolean

true 属性が適用されるメソッドが、指定した methodTypeのデータ オブジェクトの既定のメソッドであることを示す場合は。それ以外の場合は false

次のコード例では、パブリックに公開されているメソッドに DataObjectMethodAttribute 属性を適用し、実行するデータ操作の種類と、それが型の既定のデータ メソッドであるかどうかを識別する方法を示します。 この例では、 NorthwindData 型は 2 つのデータ メソッドを公開しています。1 つは GetAllEmployees という名前のデータ セットを取得し、もう 1 つは DeleteEmployeeByID という名前のデータを削除するメソッドです。 DataObjectMethodAttribute属性は両方のメソッドに適用され、GetAllEmployees メソッドはデータの選択操作の既定のメソッドとしてマークされ、DeleteEmployeeByID メソッドはデータの削除操作の既定のメソッドとしてマークされます。

[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

適用対象