DataObjectMethodAttribute 构造函数

定义

初始化 DataObjectMethodAttribute 类的新实例。

重载

DataObjectMethodAttribute(DataObjectMethodType)

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

DataObjectMethodAttribute(DataObjectMethodType, Boolean)

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

DataObjectMethodAttribute(DataObjectMethodType)

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 方法标记为选择数据操作的默认方法,方法 DeleteEmployeeByID 标记为删除数据操作的默认方法。

[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

注解

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

适用于

DataObjectMethodAttribute(DataObjectMethodType, Boolean)

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

true 指示该特性所应用于的方法是指定的 methodType 的数据对象的默认方法;否则为 false

示例

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

[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

适用于