Should we use Entity Framework

asp.netasp.net-mvcentity-frameworkwebforms

We currently have the following stack :

  • VS 2005
  • Web forms
  • SQL Server 2005
  • IIS 6

We are planning on transitioning to this :

  • VS 2010
  • MVC and Web Forms
  • SQL Server 2008
  • IIS 7

My question is, when we move to MVC with VS 2010, should we use Entity Framework( or another ORM), a micro ORM (like Massive), or just plain SQL?

All the tutorials I've read about VS 2010 are all geared towards using Entity Framework for data transactions, but is that going to be around for the foreseeable future (5+ years)?

If it matters, our client's applications can have anywhere from 10 – 1,000 active users.

Best Answer

I recently switched from using in-line SQL queries to using EF and here's what I've found:

Pros

  • Much faster to build the DAL (love not writing the SQL queries!)
  • Much easier to maintain
  • No longer need to remember to parse my input before building an in-line sql statement, which means less chance of a SQL injection attack (of course, it's still possible depending on your queries, but much less likely)

Cons

  • Cannot span multiple databases... at least not easily
  • All entities (tables, views, etc) need a primary key
  • If you want to update a single column in a 100+ required columns table (not my table design), you have to pull down all 100 columns to make the update. Or use a Stored Procedure.
  • I've had issues with some default values defined on SQL server not getting pulled into the entity model after a new record gets added. Usually this is with computed values, or values that get added in an INSERT Trigger
  • On occasion, the SQL queries get badly written and are slow to execute. If you have a slow-running query, run a SQL trace to see what EF is doing. It's possible you can re-work that query as a SP or View. This doesn't happen that often though.
  • I've had a few issues with trying to create an association between tables that do not have a Foreign Key defined in SQL Server. Usually it's because I'm trying to create a 1:0-1 relationship where EF wants to use a 1:0-*

I'm no EF expert though, so I probably missed some things. These are just the items I know I've encounted in the past when switching from inline SQL to Entity Framework. I am glad I made the switch, but there have been times when I've really hated EF due to its quirks.