DataObjectMethodAttribute Konstruktorer

Definition

Initierar en ny instans av DataObjectMethodAttribute klassen.

Överlagringar

Name Description
DataObjectMethodAttribute(DataObjectMethodType)

Initierar en ny instans av DataObjectMethodAttribute klassen och identifierar vilken typ av dataåtgärd metoden utför.

DataObjectMethodAttribute(DataObjectMethodType, Boolean)

Initierar en ny instans av DataObjectMethodAttribute klassen, identifierar vilken typ av dataåtgärd metoden utför och identifierar om metoden är den standarddatametod som dataobjektet exponerar.

DataObjectMethodAttribute(DataObjectMethodType)

Källa:
DataObjectMethodAttribute.cs
Källa:
DataObjectMethodAttribute.cs
Källa:
DataObjectMethodAttribute.cs
Källa:
DataObjectMethodAttribute.cs
Källa:
DataObjectMethodAttribute.cs

Initierar en ny instans av DataObjectMethodAttribute klassen och identifierar vilken typ av dataåtgärd metoden utför.

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)

Parametrar

methodType
DataObjectMethodType

Ett av de DataObjectMethodType värden som beskriver den dataåtgärd som metoden utför.

Exempel

I följande kodexempel visas hur du kan tillämpa DataObjectMethodAttribute attributet på en offentligt exponerad metod och identifiera vilken typ av dataåtgärd det utför samt om det är typens standarddatametod. I det här exemplet NorthwindData exponerar typen två datametoder: en för att hämta en uppsättning data med namnet GetAllEmployeesoch en annan för att ta bort data med namnet DeleteEmployeeByID. Attributet DataObjectMethodAttribute tillämpas på båda metoderna, GetAllEmployees metoden markeras som standardmetod för åtgärden Välj data och DeleteEmployeeByID metoden markeras som standardmetod för åtgärden Ta bort data.

[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

Kommentarer

Egenskapen IsDefault är inställd på false när du skapar ett DataObjectMethodAttribute objekt med den här DataObjectMethodAttribute(DataObjectMethodType) konstruktorn.

Gäller för

DataObjectMethodAttribute(DataObjectMethodType, Boolean)

Källa:
DataObjectMethodAttribute.cs
Källa:
DataObjectMethodAttribute.cs
Källa:
DataObjectMethodAttribute.cs
Källa:
DataObjectMethodAttribute.cs
Källa:
DataObjectMethodAttribute.cs

Initierar en ny instans av DataObjectMethodAttribute klassen, identifierar vilken typ av dataåtgärd metoden utför och identifierar om metoden är den standarddatametod som dataobjektet exponerar.

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)

Parametrar

methodType
DataObjectMethodType

Ett av de DataObjectMethodType värden som beskriver den dataåtgärd som metoden utför.

isDefault
Boolean

true för att ange den metod som attributet tillämpas på är standardmetoden för dataobjektet för det angivna methodType, annars false.

Exempel

I följande kodexempel visas hur du kan tillämpa DataObjectMethodAttribute attributet på en offentligt exponerad metod och identifiera vilken typ av dataåtgärd det utför samt om det är typens standarddatametod. I det här exemplet NorthwindData exponerar typen två datametoder: en för att hämta en uppsättning data med namnet GetAllEmployeesoch en annan för att ta bort data med namnet DeleteEmployeeByID. Attributet DataObjectMethodAttribute tillämpas på båda metoderna, GetAllEmployees metoden markeras som standardmetod för åtgärden Välj data och DeleteEmployeeByID metoden markeras som standardmetod för åtgärden Ta bort data.

[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

Gäller för