R – Choosing an ORM for a “simple” SaaS startup (ASP.NET MVC)

asp.net-mvcorm

I'm about to start developing a web-based application that I can best describe as a specialized version of 37Signal's Highrise contact management app, targeted towards service businesses such as lawn care. I've decided to use ASP.NET MVC to take advantage of my BizSpark membership and to leverage the C#/ASP.NET/SQL Server that I already know.

I'm doing a bit of research to choose an ORM for the project; I'm not sure if I should go with something lightweight such as LINQ to SQL or go with the big guns of NHibernate. At this point I don't envision the application as being overly complex. I essentially have these models:

  • Account
  • User (provided by ASP.NET, but I might need to extend it)
  • Customer
  • Job

where the following business rules apply:

  1. The account is the master record (since it represents a subscriber) and everything else (users, customers, jobs) hang off it
  2. A customer can have more than one job
  3. There are two types of Customers: A "lead" and a "customer" – the idea is that customers can request a followup from a form that we provide and be automatically added to the account's customer database, and then an employee can follow up and schedule a job, which "converts" the lead
  4. A job can be either one-time or set on a recurring schedule (e.g. every two weeks, once a month)

I have a bad habit of trying to overarchitect things. LINQ to SQL seems like it would suit my needs immediately, but I'm concerned about scalability in the future and whether the upfront costs of using a more feature-rich ORM such as Entity Framework or NHibernate would make up for itself in query effectiveness and optimization. I'm considering using Windows Azure to host the application.

Any thoughts?

Best Answer

Your model seems simple enough to be supported by Linq2Sql, Entity Framework, and NHibernate.

The biggest choice you need to make is do you want to follow a Domain Driven Design approach to software modeling or do you want to work with your objects as database rows. If you want to get fancy when mapping rows to objects NHibernate is the best choice. If your happy with a 1:1 between your business objects and database rows Linq2Sql and Entity Framework just fine.

NHibernate and to an extent Entity Framework support POCO objects that don't inherit from a base class and can be unaware of their persistence requirements. Linq2Sql can, but its hacky and weird.

As far as scaling goes all three of those ORM tools will get you pretty far yet AFAIK NHibernate has more options when it comes to splitting database servers up and handling cross-database IDs and there is even some Sharding support in the works.

NHibernate also supports the most providers, you can go from MSSql to MySql in an hour, with Linq2Sql and EF ( although support is forthcoming you can't )

So TL;DR:

  • NHibernate if you want better POCO support, more scaling features, and "there is a mapping for that" row->object mapping features. FluentNHibernate is awesome. You have multiple provider support
  • Entity Framework if you want better designer GUI support and are willing to wait for EF4, vs2010 for a fully featured ORM.
  • Linq2Sql if simple db access is all you need.

I've used all three and I'm least happy with EF1, EF4 is better but not as good as NHibernate.

I'm using EF4 with VS 2010 for all future "simple CRUD" apps and NHibernate when I need to get fancy.