TDD and MVC Crossroads. What ORM integrates nicely?

246 views Asked by At

I'm just starting out in MVC world, and I've used a standard MVC template that's built into VS 2010. I've got a couple of controllers and views hooked up, and now I need to get to my database.

I've got an existing SQL Server 2005 database that is quite large, already defined by a 3rd party company. I'm trying to bolt on a reporting/admin interface to it for our specific company needs.

So, I'd like, initially to just pull a list of things out of a few tables from this DB. So...using MVC 3, what are some ORM tools that integrate nicely?

I'm also trying to use a Test Drive Design approach. I'm not sure what to do for tests that would require insert/update/delete of data. Is that were "Mocks" come into play?

2

There are 2 answers

0
John Farrell On BEST ANSWER

Every ORM integrates nicely with Asp.net MVC. There is nothing in asp.net mvc that would make ORM integration hard.

Your biggest hurdle is using a legacy database. NHibernate and Entity Framework 4 are the only two free ORMs I'm aware of that map to legacy databases well. EF4 isn't too bad at mapping to legacy databases it just works better with green field development. In contrast NHibernate can map almost any scenario you can think of.

Testing ease is going to be mostly dependent on which data access pattern to use. The Repository pattern is popular because of how friendly it is to test with. No mocking is required.

4
the_drow On

I strongly suggest you to use the Castle components: Windsor, Dynamic Proxy and Active Record. You can basically mock the data since Active Record creates a model with attributes that allow you to manipulate it manually or through Dynamic Proxy's interceptors. Wrap up repositories and data services to gain more control of your data access.
Use the specifition pattern where applicable to allow flexiable querying easily.
Use Linq with Active Record in your data services in order to be able to pass IEnumerable<T> or specifications (that may or may not wrap NHibernate's abstract criteria and convert them to a DetachedCriteria or may contain the DetachedCriteria or an HQL or whatever you are encapsuling) as queries.
That way you can mock your database access easily and refactor and test more easily.