All the basics of the Matisse post-relational database have already been covered by this series of articles, along with its advantages, such as ease of use and better performance.
This article covers ASP.NET programming with the post-relational database. I have created two demo programs to illustrate this article. The first one is a Windows application that loads data with images into a database. The second one is an ASP.NET application that retrieves the images with meta data from the database and displays them using
DataList. The programs are straightforward but there are a few tips that make the programs more compact and provide better performance.
Here is the list of previous articles:
- Part 1: Overview of Matisse.
- Part 2: Schema definition.
- Part 3: .NET programming to insert objects.
- Part 4: Using ADO.NET to retrieve objects.
- Part 5: Using Object-APIs for better performance.
Running the Demo
To compile and run the demo applications, first download the source file attached at the beginning of this article. Create a new blank solution in Visual Studio .NET 2003 and add three projects: a Class Library (DbSchema), a Windows Application (MediaDemo), and an ASP.NET application (MediaDemoASP) as shown in the next figure. Extract all the files from the downloaded zip file, and add the files to the three projects accordingly.
In the Matisse Enterprise Manager, start the ‘media’ database and import the ODL file demo.odl included in the zip file to load the database schema (Select the media database icon, right click on it, select Schema --> Import ODL Schema).
Compile the three .NET projects and run the MediaDemo Windows application to load the data. You will see the following window, and then select the folder photos which you downloaded with other source files, and click the ‘Load Data’ button to load the image data into the database. After loading the data, you can view the imported data in the ‘View Data’ tab.
To run the ASP.NET demo from Visual Studio .NET, select the ‘MediaDemoASP’ project as ‘Startup Project’ and select ‘StartForm.aspx’ as ‘Start Page’.
The ASP.NET demo uses
DataList Web Control to display a list of photos with descriptions, four photos in each page as shown in the figure at the top of this article. It uses the
OFFSET clauses in the
SELECT statement to limit the number of rows returned, starting from a certain offset. Note that the
SELECT statement returns the
OID (Object Identifier, equivalent with primary key) column as well, which will be used to retrieve images efficiently. The rest is textbook programming with the
string query =
"SELECT Title, Description, OID FROM Photo ORDER BY Title " +
" LIMIT " + PageSize +
" OFFSET " + (CurrentPage * PageSize);
MtCommand cmd = db.CreateCommand();
cmd.CommandText = query;
MtDataReader reader = (MtDataReader) cmd.ExecuteReader();
DataList1.DataSource = reader;
In the web form that contains the
DataList, specify the thumbnail image URL using the
OID column as follows:
<asp:Image … ImageUrl=
'<%# PhotoThumbnailURL((string) DataBinder.Eval(Container.DataItem, "OID")) %>'>
PhotoThumbnailURL which takes
OID as an input parameter is defined as follows:
public string PhotoThumbnailURL(string oid)
return "ReadThumbnail.aspx?oid=" + oid +
"&dbname=" + (string) ViewState["DbName"];
The next piece of code from ReadThumbnail.aspx.cs parses the passed
OID string into an integer. Then, it creates a
Photo object, which is a Matisse object, using a constructor that takes the OID (line A). Since it does not use SQL statements, it retrieves the object faster from the database. To get the thumbnail image data, access the
Thumbnail property of the
Photo object (line B).
byte imgdata = null;
int oid = Int32.Parse(Request.QueryString["oid"].Substring(2),
Photo photo = new Photo(db, oid);
imgdata = photo.Thumbnail;
if ( null != imgdata )
The article showed a simple ASP.NET application that retrieves image data along with some descriptions from the Matisse database and displays the data using the
<< Back | Next >>
John is a software consultant and currently working for a large .NET project. He has an extensive experience in object-oriented technologies for more than 15 years ranging from Smalltalk, C++, Java, .NET to databases.