Building OpenPOS: Part 10 – Code First

Historically Microsoft has always focused on the “Database first” model, where you build a database and then from this database create a data layer… With Entity Framework 4, we now can do what is referred to as “Model first” design. The scenario I am really interested in though is “Code first”! Since the release of EF4, Microsoft has been pushing out some feature CTPs. These are previews of what they have planned for the future. The interesting thing here is the new “Code first” support, where we can create POCOs (Plain old CLR objects) and then use EF’s new DbContext/DbSet to persist them! This is a very transparent convention over configuration based method of persisting data.

“Convention over Configuration (also known as Coding by convention) is a software design paradigm which seeks to decrease the number of decisions that developers need to make, gaining simplicity, but not necessarily losing flexibility.”

First things first, I need to create a POCO object for each of my model classes (Like products, customers, etc.). Here is a sample: