DataObjectAttribute 构造函数
定义
初始化 DataObjectAttribute 类的新实例。Initializes a new instance of the DataObjectAttribute class.
重载
| DataObjectAttribute() |
初始化 DataObjectAttribute 类的新实例。Initializes a new instance of the DataObjectAttribute class. |
| DataObjectAttribute(Boolean) |
初始化 DataObjectAttribute 类的新实例,并指示某一对象是否适合绑定到 ObjectDataSource 对象。Initializes a new instance of the DataObjectAttribute class and indicates whether an object is suitable for binding to an ObjectDataSource object. |
DataObjectAttribute()
初始化 DataObjectAttribute 类的新实例。Initializes a new instance of the DataObjectAttribute class.
public:
DataObjectAttribute();
public DataObjectAttribute ();
Public Sub New ()
示例
下面的代码示例演示如何使用 DataObjectAttribute() 构造函数。The following code example demonstrates using the DataObjectAttribute() constructor.
[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
注解
IsDataObject true 使用构造函数时,属性设置为 DataObjectAttribute() 。The IsDataObject property is set to true when you use the DataObjectAttribute() constructor.
适用于
DataObjectAttribute(Boolean)
初始化 DataObjectAttribute 类的新实例,并指示某一对象是否适合绑定到 ObjectDataSource 对象。Initializes a new instance of the DataObjectAttribute class and indicates whether an object is suitable for binding to an ObjectDataSource object.
public:
DataObjectAttribute(bool isDataObject);
public DataObjectAttribute (bool isDataObject);
new System.ComponentModel.DataObjectAttribute : bool -> System.ComponentModel.DataObjectAttribute
Public Sub New (isDataObject As Boolean)
参数
- isDataObject
- Boolean
如果该对象适合绑定到 ObjectDataSource 对象,则为 true;否则为 false。true if the object is suitable for binding to an ObjectDataSource object; otherwise, false.
注解
使用 DataObjectAttribute(Boolean) 构造函数向设计时类(例如 ObjectDataSourceDesigner 应从适当对象列表中排除对象的类)指示用于绑定到对象的类 ObjectDataSource 。Use the DataObjectAttribute(Boolean) constructor to indicate to a design-time class such as the ObjectDataSourceDesigner class that an object should be excluded from the list of suitable objects for binding to an ObjectDataSource object.
此 IsDataObject 属性设置为参数的值 isDataObject 。The IsDataObject property is set to the value of the isDataObject parameter.