Monthly Archives: July 2013

Code-First Development with Entity Framework 5.0

By Tim Daniels
As you know from previous posts, I prefer using an Object Relational Mapping (ORM) framework, as part of a domain driven approach to design and development of a business solution. The Microsoft ADO.NET Entity Framework is an Object Relational Mapping framework that enables developers to work with relational data as domain-specific objects, eliminating the need for most of the data access plumbing code that developers usually need to write. Developers can focus on their application-specific business logic rather than the data access fundamentals.

Recent development in the ADO.NET Entity Framework provide further support for two other software development techniques, which I find very appealing and effective, in design and development of new solutions.

  • Code-First Development Workflow
  • Convention over configuration

The code first approach offers several advantages to the application developer. It allows the developer to focus on domain specific entity classes and how these classes relate to each other in the business model. These classes are completely independent of a database source, the ORM and any third-party attributes. They are also independent of any base class inheritance. These classes are sometimes refered to as plain old common language runtime objects or POCO classes.

The entity classes form a set of conventions which the ADO.Net Entity Framework uses to automatically generate an object model and a SQL Server relational database.

Here is an example of two POCO entity classes. A time sheet object and a time sheet entry object. There is a one to many relationship between the time sheet object and the time sheet entry objects. This relationship is expressed by the TimeSheetEntries property of the TimeSheet class. This is known as a navigational property.

In the near future, I’ll be writing a series of posts on the Code-First development workflow, and then follow-up with a post on how code first ties into the convention over configuration development technique.

Here are several helpful links to help you get familiar with Entity Framework Development Workflows and the code-first workflow.