It is now time to create the first real page, the Contacts Form, and the database tables to support it.
But there is a problem. I use LLBLGen, an Object Relational Mapper, which maps my database tables to classes. It creates a number of classes:
- Entity classes – the classes which map to the tables
- Collection classes – collections of entities
- Typed List classes – read only lists which include the specific fields from tables or relations that I might want to use, for example in list boxes
- Classes formed from relationships that I establish
- Various factory and helper classes for sorting, filtering and other assorted functions.
While there is no problem with the Contact entity, or table, that I will create, It is worthwhile mentioning here the procedure that I follow.
Data is held in a relational database, which follows fairly strict rules. Relational databases can be described in purely mathematical terms, and there is a well-deveoped relational theory to support them.
But the object which I use to populate the controls on the forms, such as text boxes, list boxes, etc, do not necessarily relate 1 to 1 with the tables. So my thinking is in terms of the objects and classes, but my O/R mapper does not translate classes into data tables, rather it maps data tables onto classes.
So I need to consider, first what objects I want to show, and from those determine the data that is needed to create these objects. Once that is done I can then apply relational theory to create the database tables. The O/R mapper then generates my classes which I use to create the objects.
As I said earlier, it is not a problem with the Contacts table or classes. I will create a table for Contacts and map it directly to a Contacts entity.
The Contacts table will consist of the following fields, or attributes, or columns, depending upon your prefered nomenclature – isn’t that a great word!
- ContactID, the primary key and we will make it autoincrement
- CompanyName
- Surname – the surname of the contact person within the company
- FirstName
- Add1 – the street number and name, or post office box
- Add2 – the town or suburb
- Postcode
- State – that is geographical state, like NSW, VIC etc
- Phone
- Mobile
I have realised that I left fax out of this. I have already built the form, but I have made a note to amend it, at some stage soon.
The next thing to do is to create the form, the subject of the next article.