通过


DataObjectMethodAttribute 构造函数

定义

初始化 DataObjectMethodAttribute 类的新实例。

重载

名称 说明
DataObjectMethodAttribute(DataObjectMethodType)

初始化类的新实例 DataObjectMethodAttribute ,并标识方法执行的数据操作的类型。

DataObjectMethodAttribute(DataObjectMethodType, Boolean)

初始化类的新实例 DataObjectMethodAttribute ,标识方法执行的数据操作的类型,并标识该方法是否为数据对象公开的默认数据方法。

DataObjectMethodAttribute(DataObjectMethodType)

Source:
DataObjectMethodAttribute.cs
Source:
DataObjectMethodAttribute.cs
Source:
DataObjectMethodAttribute.cs
Source:
DataObjectMethodAttribute.cs
Source:
DataObjectMethodAttribute.cs

初始化类的新实例 DataObjectMethodAttribute ,并标识方法执行的数据操作的类型。

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)

参数

methodType
DataObjectMethodType

DataObjectMethodType描述该方法执行的数据操作的值之一。

示例

下面的代码示例演示如何将 DataObjectMethodAttribute 属性应用于公开的方法,并标识它执行的数据操作的类型以及它是否为类型的默认数据方法。 在此示例中,该 NorthwindData 类型公开两个数据方法:一个用于检索一组命名 GetAllEmployees的数据,另一个用于删除命名 DeleteEmployeeByID的数据。 该 DataObjectMethodAttribute 属性应用于这两种方法, GetAllEmployees 该方法被标记为 Select 数据操作的默认方法,该方法 DeleteEmployeeByID 被标记为 Delete 数据操作的默认方法。

[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

注解

使用此构造函数创建DataObjectMethodAttribute对象时,该IsDefault属性将设置为falseDataObjectMethodAttribute(DataObjectMethodType)属性。

适用于

DataObjectMethodAttribute(DataObjectMethodType, Boolean)

Source:
DataObjectMethodAttribute.cs
Source:
DataObjectMethodAttribute.cs
Source:
DataObjectMethodAttribute.cs
Source:
DataObjectMethodAttribute.cs
Source:
DataObjectMethodAttribute.cs

初始化类的新实例 DataObjectMethodAttribute ,标识方法执行的数据操作的类型,并标识该方法是否为数据对象公开的默认数据方法。

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)

参数

methodType
DataObjectMethodType

DataObjectMethodType描述该方法执行的数据操作的值之一。

isDefault
Boolean

如果指示属性应用于的方法是指定 数据对象的默认方法,则为 ;否则为 < a1/ >。

示例

下面的代码示例演示如何将 DataObjectMethodAttribute 属性应用于公开的方法,并标识它执行的数据操作的类型以及它是否为类型的默认数据方法。 在此示例中,该 NorthwindData 类型公开两个数据方法:一个用于检索一组命名 GetAllEmployees的数据,另一个用于删除命名 DeleteEmployeeByID的数据。 该 DataObjectMethodAttribute 属性应用于这两种方法, GetAllEmployees 该方法被标记为 Select 数据操作的默认方法,该方法 DeleteEmployeeByID 被标记为 Delete 数据操作的默认方法。

[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

适用于