DataObjectMethodAttribute Konstruktoren

Definition

Initialisiert eine neue Instanz der DataObjectMethodAttribute-Klasse.

Überlädt

DataObjectMethodAttribute(DataObjectMethodType)

Initialisiert eine neue Instanz der DataObjectMethodAttribute-Klasse und identifiziert den Typ des von der Methode ausgeführten Datenvorgangs.

DataObjectMethodAttribute(DataObjectMethodType, Boolean)

Initialisiert eine neue Instanz der DataObjectMethodAttribute-Klasse, identifiziert den Typ des von der Methode ausgeführten Datenvorgangs, und gibt an, ob die Methode die vom Datenobjekt verfügbar gemachte Standarddatenmethode darstellt.

DataObjectMethodAttribute(DataObjectMethodType)

Quelle:
DataObjectMethodAttribute.cs
Quelle:
DataObjectMethodAttribute.cs
Quelle:
DataObjectMethodAttribute.cs

Initialisiert eine neue Instanz der DataObjectMethodAttribute-Klasse und identifiziert den Typ des von der Methode ausgeführten Datenvorgangs.

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)

Parameter

methodType
DataObjectMethodType

Einer der DataObjectMethodType-Werte, mit denen der von der Methode ausgeführte Vorgang beschrieben wird.

Beispiele

Im folgenden Codebeispiel wird veranschaulicht, wie Sie das DataObjectMethodAttribute Attribut auf eine öffentlich zugängliche Methode anwenden und den Typ des ausgeführten Datenvorgangs sowie die Standarddatenmethode des Typs identifizieren können. In diesem Beispiel macht der NorthwindData Typ zwei Datenmethoden verfügbar: eine zum Abrufen eines Datensatzes mit dem Namen GetAllEmployeesund eine andere zum Löschen von Daten mit dem Namen DeleteEmployeeByID. Das DataObjectMethodAttribute Attribut wird auf beide Methoden angewendet, die GetAllEmployees -Methode wird als Standardmethode für den Select-Datenvorgang markiert, und die DeleteEmployeeByID -Methode ist als Standardmethode für den Vorgang "Daten löschen" gekennzeichnet.

[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

Hinweise

Die IsDefault -Eigenschaft wird auf false festgelegt, wenn Sie ein DataObjectMethodAttribute Objekt mit diesem DataObjectMethodAttribute(DataObjectMethodType) Konstruktor erstellen.

Gilt für:

DataObjectMethodAttribute(DataObjectMethodType, Boolean)

Quelle:
DataObjectMethodAttribute.cs
Quelle:
DataObjectMethodAttribute.cs
Quelle:
DataObjectMethodAttribute.cs

Initialisiert eine neue Instanz der DataObjectMethodAttribute-Klasse, identifiziert den Typ des von der Methode ausgeführten Datenvorgangs, und gibt an, ob die Methode die vom Datenobjekt verfügbar gemachte Standarddatenmethode darstellt.

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)

Parameter

methodType
DataObjectMethodType

Einer der DataObjectMethodType-Werte, mit denen der von der Methode ausgeführte Vorgang beschrieben wird.

isDefault
Boolean

true, um anzugeben, dass die Methode, auf die das Attribut angewendet wird, die Standardmethode des Datenobjekts für den angegebenen methodType darstellt, andernfalls false.

Beispiele

Im folgenden Codebeispiel wird veranschaulicht, wie Sie das DataObjectMethodAttribute Attribut auf eine öffentlich zugängliche Methode anwenden und den Typ des ausgeführten Datenvorgangs sowie die Standarddatenmethode des Typs identifizieren können. In diesem Beispiel macht der NorthwindData Typ zwei Datenmethoden verfügbar: eine zum Abrufen eines Datensatzes mit dem Namen GetAllEmployeesund eine andere zum Löschen von Daten mit dem Namen DeleteEmployeeByID. Das DataObjectMethodAttribute Attribut wird auf beide Methoden angewendet, die GetAllEmployees -Methode wird als Standardmethode für den Select-Datenvorgang markiert, und die DeleteEmployeeByID -Methode ist als Standardmethode für den Vorgang "Daten löschen" gekennzeichnet.

[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

Gilt für: