DataObjectMethodAttribute Konstruktorok

Definíció

Inicializálja a DataObjectMethodAttribute osztály új példányát.

Túlterhelések

Name Description
DataObjectMethodAttribute(DataObjectMethodType)

Inicializálja az DataObjectMethodAttribute osztály új példányát, és azonosítja a metódus által végrehajtott adatművelet típusát.

DataObjectMethodAttribute(DataObjectMethodType, Boolean)

Inicializálja az DataObjectMethodAttribute osztály új példányát, azonosítja a metódus által végrehajtott adatművelet típusát, és azonosítja, hogy az adatobjektum által elérhetővé tévő alapértelmezett adatmetódus-e a metódus.

DataObjectMethodAttribute(DataObjectMethodType)

Forrás:
DataObjectMethodAttribute.cs
Forrás:
DataObjectMethodAttribute.cs
Forrás:
DataObjectMethodAttribute.cs
Forrás:
DataObjectMethodAttribute.cs
Forrás:
DataObjectMethodAttribute.cs

Inicializálja az DataObjectMethodAttribute osztály új példányát, és azonosítja a metódus által végrehajtott adatművelet típusát.

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)

Paraméterek

methodType
DataObjectMethodType

DataObjectMethodType A metódus által végrehajtott adatműveletet leíró értékek egyike.

Példák

Az alábbi példakód bemutatja, hogyan alkalmazhatja az DataObjectMethodAttribute attribútumot egy nyilvánosan közzétett metódusra, és hogyan azonosíthatja az általa végrehajtott adatművelet típusát, valamint azt, hogy ez-e a típus alapértelmezett adatmetódusa. Ebben a példában a NorthwindData típus két adatmetelyt tesz elérhetővé: az egyik egy elnevezett GetAllEmployeesadatkészlet lekéréséhez, a másik pedig a névvel ellátott DeleteEmployeeByIDadatok törléséhez. Az DataObjectMethodAttribute attribútum mindkét metódusra alkalmazva van, a GetAllEmployees metódus az adatválasztási művelet alapértelmezett metódusaként van megjelölve, a DeleteEmployeeByID metódus pedig az adattörlési művelet alapértelmezett metódusaként van megjelölve.

[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

Megjegyzések

A IsDefault tulajdonság akkor van beállítvafalse, ha ezzel a DataObjectMethodAttribute konstruktorsal hoz létre objektumotDataObjectMethodAttribute(DataObjectMethodType).

A következőre érvényes:

DataObjectMethodAttribute(DataObjectMethodType, Boolean)

Forrás:
DataObjectMethodAttribute.cs
Forrás:
DataObjectMethodAttribute.cs
Forrás:
DataObjectMethodAttribute.cs
Forrás:
DataObjectMethodAttribute.cs
Forrás:
DataObjectMethodAttribute.cs

Inicializálja az DataObjectMethodAttribute osztály új példányát, azonosítja a metódus által végrehajtott adatművelet típusát, és azonosítja, hogy az adatobjektum által elérhetővé tévő alapértelmezett adatmetódus-e a metódus.

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)

Paraméterek

methodType
DataObjectMethodType

DataObjectMethodType A metódus által végrehajtott adatműveletet leíró értékek egyike.

isDefault
Boolean

true az attribútum által alkalmazott metódust jelzi a megadott methodTypeadatobjektum alapértelmezett metódusa; ellenkező esetben false.

Példák

Az alábbi példakód bemutatja, hogyan alkalmazhatja az DataObjectMethodAttribute attribútumot egy nyilvánosan közzétett metódusra, és hogyan azonosíthatja az általa végrehajtott adatművelet típusát, valamint azt, hogy ez-e a típus alapértelmezett adatmetódusa. Ebben a példában a NorthwindData típus két adatmetelyt tesz elérhetővé: az egyik egy elnevezett GetAllEmployeesadatkészlet lekéréséhez, a másik pedig a névvel ellátott DeleteEmployeeByIDadatok törléséhez. Az DataObjectMethodAttribute attribútum mindkét metódusra alkalmazva van, a GetAllEmployees metódus az adatválasztási művelet alapértelmezett metódusaként van megjelölve, a DeleteEmployeeByID metódus pedig az adattörlési művelet alapértelmezett metódusaként van megjelölve.

[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

A következőre érvényes: