Tag Archives: csharp

Data Access Layer decisions

I am now more than 3 months into the development of a greenfield application for my employer.  In October, after 2 weeks of heated discussions and gnashing of teeth (jk), we decided on using the Entity Framework as a data access layer for this project. This decision came about for the following reasons:

  • Abstraction of database access, allowing us to focus on the business entities we need to construct
  • Automatic generation of SQL to access the database, significantly reducing the amount of code we need to hand-write
  • Through a simple repository model and partial class structure, we’re empowered to easily abstract the data access and unit test our service layers
  • This is a known tool distributed by Microsoft that any .Net developer who is actively working should have some familiarity with

This decision has allowed us to our application without needing any hand-written SQL stored-procedures or functions.  All of our business logic is encapsulated in a service layer that is 98% covered with unit tests.  This assurance provided by the service layer gives our team the confidence to make changes to the data access layer without significantly impacting the rest of the application.

Our application lives in a hosted web application model, that is attempting to achieve 99.99% uptime.  To meet these needs, we have redundant web servers, redundant application servers, but only 1 database.  As a software analyst, I want to protect the database processors and memory from unnecessary work.  To that end, I want to move as much business logic away from this single point of failure so that it can focus on what it does best: store and retrieve data.

When we do need something more sophisticated to access data from the database, we can augment our model with stored procedures that populate and maintain our entities.

Our project team has profiled our Entity Framework code, and have not found any significant “n+1” query issues.  I will find it very hard to believe that anyone would want us to write additional SQL code, that needs to be maintained. Entity Framework is already generating and maintaining that code for us automatically.