Friday, February 13, 2009

Building a business class to work with ObjectDataSource

The ObjectDataSource enables us to bind a UI control to a business class instead of accessing the database directly from the UI.
There are many on-line articles that explains this in details, and I will not do that here. I will give some tips and give some answers to questions I could not find anywhere and eventually found using trial and error.
  • The business class can be defined using the [System.ComponentModel.DataObject] attribute, but it does not have to. When selecting the business class of the ObjectDataSource, we can select if we want to choose only from data components or not.
  • The simplest way to define the methods used by the ObjectDataSource is making them static. That way we do not have to worry about instantiation and initialization of the class.
  • The ObjectDataSource reads the public properties of the returned objects of the select method. Even if there are public members, they will not be visible to the controls using the ObjectDataSource as their source.

No comments:

Post a Comment