Useful attributes for working with ObjectDataSource
1. DataObjectAttribute
Use the DataObjectAttribute attribute to identify an object as suitable for use by an ObjectDataSource object. Design-time classes such as the
2. DataObjectMethodAttribute
You can use the DataObjectMethodAttribute to identify data operation methods on a type marked with the DataObjectAttribute attribute so that they are more easily identified by callers using reflection. When the DataObjectMethodAttribute attribute is applied to a method, it describes the type of operation the method performs and indicates whether the method is the default data operation method of a type
Example:
[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);
}
[DataObjectMethodAttribute(DataObjectMethodType.Delete, true)]
public void DeleteEmployeeByID(int employeeID)
{
throw new Exception("The value passed to the delete method is " + employeeID.ToString());
}
}