A great way to work with NHibernate data and data-bound controls is to populate the controls with an <asp:ObjectDataSource>
. This control allows you to specify what type of objects the control will return (DataObjectTypeName
) and what object the control will need to access to perform the CRUD operations (TypeName
).
The basic <asp:ObjectDataSource>
control just needs four things to get it going, namely, an ID, a DataObjectTypeName (POCO), a Type Name (Data Access Object), and a CRUD method (Create, Read, Update, and Delete). A sample <asp:ObjectDataSource>
to retrieve all of the OrderHeader items in the database would look like this:
<asp:ObjectDataSource ID="orderHeaderSource" DataObjectTypeName="Ordering.Data.OrderHeader"TypeName="Ordering.Data.DataAccess.OrderHeaderDataControl" SelectMethod="GetAll" runat="server"> </asp:ObjectDataSource>
Now that we have the ID (orderHeaderSource
), we can use it in any data-bound control...