Freigeben über


DataObjectMethodAttribute Konstruktoren

Definition

Initialisiert eine neue Instanz der DataObjectMethodAttribute-Klasse.

Überlädt

Name Beschreibung
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 es sich bei der Methode um die Standarddatenmethode handelt, die das Datenobjekt verfügbar macht.

DataObjectMethodAttribute(DataObjectMethodType)

Quelle:
DataObjectMethodAttribute.cs
Quelle:
DataObjectMethodAttribute.cs
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 Datenvorgang beschrieben wird, den die Methode ausführt.

Beispiele

Im folgenden Codebeispiel wird veranschaulicht, wie Sie das DataObjectMethodAttribute Attribut auf eine öffentlich verfügbar gemachte Methode anwenden und den Typ des von ihr ausgeführten Datenvorgangs identifizieren sowie ob es sich um die Standarddatenmethode des Typs handelt. In diesem Beispiel macht der NorthwindData Typ zwei Datenmethoden verfügbar: eine zum Abrufen einer Datenmenge namens 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 wird als Standardmethode für den Löschdatenvorgang markiert.

[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 festgelegt false , 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
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 es sich bei der Methode um die Standarddatenmethode handelt, die das Datenobjekt verfügbar macht.

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 Datenvorgang beschrieben wird, den die Methode ausführt.

isDefault
Boolean

trueum die Methode anzugeben, auf die das Attribut angewendet wird, ist die Standardmethode des Datenobjekts für den angegebenen methodType; andernfalls . false

Beispiele

Im folgenden Codebeispiel wird veranschaulicht, wie Sie das DataObjectMethodAttribute Attribut auf eine öffentlich verfügbar gemachte Methode anwenden und den Typ des von ihr ausgeführten Datenvorgangs identifizieren sowie ob es sich um die Standarddatenmethode des Typs handelt. In diesem Beispiel macht der NorthwindData Typ zwei Datenmethoden verfügbar: eine zum Abrufen einer Datenmenge namens 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 wird als Standardmethode für den Löschdatenvorgang markiert.

[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: