Using Dali with ASP.NET
Using Dali for your web forms makes your
coding easier and makes your pages more extensible and maintainable. The
reason is Dali's ability to adapt to changing requirements; especially
changing database schemas. If you've read the documentation and worked
with Dali, you know that virtually any class can be mapped to a database
table with little or no additional code. Once mapped, objects of this
class can be loaded from or saved to the database with one line of code.
So why should an ASPX page be any different? Here's what you would do in
your "code behind" class:
If your page class name is the same as the name of the database table you
don't have to do anything. Dali will find the table. If the name is
different, add an attribute to your page's class declaration, telling it
which table the page maps to. For example:
[VB]
<DaliClass(TableName:="Customers")> _
Public Class Customer
Inherits System.Web.UI.Page
...
End Class
[C#]
[DaliClass(TableName="Customers")]
public class Customer : System.Web.UI.Page
{
...
}
If the controls on the page have the same
name as the columns in your table you don't have to do anything.
Dali will find them. If your control names are not the same as
your column names, add an attribute to each control declaration.
For example:
[VB]
<DaliMember(ColumnName:="CompanyName")> _
Protected WithEvents CompanyNameTextBox As _
System.Web.UI.WebControls.TextBox
[C#]
[DaliMember(ColumnName="CompanyName")]
protected System.Web.UI.WebControls.TextBox
CompanyNameTextBox;
To save the page's form data to the database, simply call the DataManager's Save method:
[VB]
DataManager.Default.Save (Page)
[C#]
DataManager.Default.Save (Page);
Loading the form from the database is just as
easy. You would first set the primary key value (in our example, the
CustomerID property) then call the Load method. You will also need a line
of code to set the connect string. But that's pretty much all you'll need
to get your web forms reading and writing to a database.
The Trial Edition comes with a full sample web solution that
uses Dali. This sample demonstrates how to load and store web forms to a
database. Download the
Dali Trial Edition
to view and run the sample.