DataObjectMethodType Enum

Definisi

Mengidentifikasi jenis operasi data yang dilakukan oleh metode , seperti yang ditentukan oleh DataObjectMethodAttribute yang diterapkan ke metode .

public enum class DataObjectMethodType
public enum DataObjectMethodType
type DataObjectMethodType = 
Public Enum DataObjectMethodType
Warisan
DataObjectMethodType

Bidang

Delete 4

Menunjukkan bahwa metode digunakan untuk operasi data yang menghapus data.

Fill 0

Menunjukkan bahwa metode digunakan untuk operasi data yang mengisi DataSet objek.

Insert 3

Menunjukkan bahwa metode digunakan untuk operasi data yang menyisipkan data.

Select 1

Menunjukkan bahwa metode digunakan untuk operasi data yang mengambil data.

Update 2

Menunjukkan bahwa metode digunakan untuk operasi data yang memperbarui data.

Contoh

Contoh kode berikut menunjukkan bagaimana Anda dapat menerapkan DataObjectMethodAttribute ke metode yang diekspos secara publik dan mengidentifikasi jenis operasi data yang dilakukannya serta apakah itu metode data default jenis. Dalam contoh NorthwindEmployee ini jenis mengekspos dua metode data yang berbeda: satu untuk mengambil sekumpulan data bernama GetAllEmployees, dan satu untuk menghapus data bernama DeleteEmployeeByID. DataObjectMethodAttribute diterapkan ke kedua metode.

[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

Berlaku untuk

Lihat juga