Home > .NET > The Entity Framework Balloon

The Entity Framework Balloon

September 10th, 2009 Josh Leave a comment Go to comments

I have used the Entity Framework for two successful project implementations. In my opinion EF lies somewhere between "awesome framework that makes application development a breeze" and "generic tool that requires too much effort to do anything besides out of the box".

Before I explain myself, I need to identify the common patterns I think are necessary in any application that needs to persist data:

Common Data Access Tasks
Design and Create Database Tables
Write SQL Statements or Stored Procedures/Packages
Design and Create Logical Entities
Write Code to Map Entities to Database
Tune Database via Indexing, Constraints, and Referential Integrity (if RDBMS)
Unit Test Data Access Methods
Handle Transactions

EF works to simplify the development for database dependent applications by removing the redundant work involved in each project. Namely, the below highlighted tasks:

Common Data Access Tasks
Design and Create Database Tables
Write SQL Statements or Stored Procedures/Packages
Design and Create Logical Entities
Write Code to Map Entities to Database
Tune Database via Indexing, Constraints, and Referential Integrity (if RDBMS)
Unit Test Data Access Methods
Handle Transactions

What is so bad about Entity Framework?

  1. Most developers do not know to optimize database operations. EF creates a sandbox so that they may do whatever the hell they want with the data. This will drive any DBA crazy when they are asked to make optimizations.
  2. With 99% confidence, I believe that most of the .NET framework code is bug-free (or has yet to become a problem for me). Knowing this, we can believe that our EF SQL queries are probably legit. But isn’t it important to test our queries themselves through unit tests? The ability to unit test our own data access methods without requiring an active database (in-memory or XML defined?) is a necessary feature.
  3. Consequently, the application is fully aware of the ties to the EF and cannot be tested without. Persistence ignorance support is necessary so that developers are not forced to implement additional interfaces or provide unnecessary references.
  4. Developing N-Tiered Applications with EF is difficult. Reattach objects into the data context after client modifications requires too much work.
  5. Lazy loading improves performance, but excess code is needed to check if a related set is loaded. If it is not loaded, additional code is required to perform the operation. Consequently, it could make database operations unnecessarily chatty.

I am only able to list five points about what is bad about the EF, after working on it for 8 months. In that time I have managed to work around two of the five issues with ADO.NET Data Services (unit testing data access methods with a mock implementation and creating N-Tiered applications). Performance issues have cropped up that I am 100% confident would not exist if custom code had been written to manage data access.

So what is the ‘Entity Framework Balloon’?

squashed_balloons

Someone once provided this analogy to me.

If our project were a water balloon, each development task would have its own piece of space. The introduction of EF attempts to shrink the cost/time to do the redundant tasks by compressing that side of the balloon. But the other tasks have to go somewhere else, and their piece just gets bigger and requires more effort in the long run.

There always seems to be a new tool for the job. EF obviously serves its purpose, but it fails at making everything as easy as it seems.

.NET 4 with the new Entity Framework

Looking ahead, the ADO.NET Team Blog has focused on a list of concerns for the next version of EF.  They are focusing on improving:

  1. Enabling settings to make development simpler such as lazy loading, eager loading, and stored procedure mapping.
  2. Improving the readability of the generated SQL.
  3. Persistence Ignorance support, allowing you to write POCO and later tie them to Entity Framework or another Data Provider.
  4. Better N-Tier Support allowing the serialized entities to include their own change tracking properties.
  5. Model-First and Code-Only development!

     

    Entity Framework Reading List:

    Anti-Patterns to Avoid in N-Tier Applications
    The Entity Framework in Layered Architectures
    What’s New and Cool in Entity Framework 4.0

Categories: .NET Tags:
  1. Dave
    September 13th, 2009 at 16:37 | #1

    “4. Developing N-Tiered Applications with EF is difficult. Reattach objects into the data context after client modifications requires too much work.”

    EF is evil for this reason alone!

  1. No trackbacks yet.