Book Image

Learning NHibernate 4

Book Image

Learning NHibernate 4

Overview of this book

Table of Contents (18 chapters)
Learning NHibernate 4
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Composite IDs


Using surrogate keys is becoming the norm these days. Database tables we have seen so far had simple surrogate primary keys. A single column named Id, of integer type, acted as primary key. In old databases, it is possible to have tables which use natural keys. Primary keys of such tables, at times, can be composed of more than one column. Such primary keys are called composite keys. Let's assume for a moment that the Employee table in our employee benefits application is such a legacy table and it does not have an Id column. In order to maintain the uniqueness of records in this table, we designate Firstname and Lastname columns to form a composite key.

Note

You could argue that we should use EmailAddress column as primary key in this instance. Well, you can, but we just wanted to see an example of composite keys on a database that we know of, instead of introducing a whole new database schema.

A barebones Employee class for this example could look as follows:

public class Employee...