views:

298

answers:

6

Well, I've been following the NerdDinner tutorial online and I've completed it to a T.

Now I've implemented a project of my own using pretty much the same architecture.

I notice my process is:

  1. Create database.
  2. Create DBML.
  3. Create |TableName|Repository.cs class with data access methods.
  4. Create partial |TableName| class to handle validation.
  5. Rinse and repeat for all tables.

By the time I'm done I'm exhausted and I haven't really done anything except drag and copypaste code and change variable names.

What am I missing here. Where can I improve this boilerplate haze I'm in?

Edit: Sans creating my own T4 template, is there a tool that will help me?

+1  A: 

Have a look at this for ideas. It uses a generic repository and the unit of work pattern.

http://elegantcode.com/2009/12/15/entity-framework-ef4-generic-repository-and-unit-of-work-prototype/

Also here.

http://stackoverflow.com/questions/1230571/advantage-of-creating-a-generic-repository-vs-specific-repository-for-each-objec

I've implemented something based on these ideas. You may also want to look at using a service layer more interfaces etc than the nerd dinner example shows.

As good as the tutorial is, it isn't IMO really fit for use in an enterprise application as it is still quite tightly coupled.

Hope this helps.

davy
+5  A: 

See Visual Studio Templates.

I haven't used them, but I assume if you take the time to customize them, you'll be able to make Visual Studio generate a lot of what you already do instantly specifically using the T4 template language/interpreter thats embedded in Visual Studio.

Baddie
A: 

I use my own tool for that: http://github.com/Necroskillz/NecroNetToolkit

It basically bypasses all the steps that u mentioned (except validation, because I have validation on my view models).

Necros
A: 

While its not directly MVC focused, I've enjoyed using NetTiers http://nettiers.com for this kind of foundation. We start with the Db tables and indexing and then generate the stored procedures and their related data and service layer code. After that we add our own custom stored procedures, creating a rich (and easily understood) foundation. Future changes are easily accommodated through this mechanism.

We also bolt the code generation into our Nant build procedures, providing a very quick way of updating all of the mundane 'plumbing' code, allowing us to concentrate on the interesting stuff.

We've just started working with MVC and have found the netTiers service layer works nicely with it - time will tell as our MVC experience grows. I hope that helps!

Elliveny
+1  A: 

I haven't used it much but perhaps you could create a codesmith template to handle this. http://www.codesmithtools.com/

I have seen it used to good effect with Nettiers and in some other scenarios.

Dean Johnston
A: 

Create a framework!

brian
There's already a framework. A lot of the work being done is about doing things the framework's way, but creating a whole other one is a pretty huge project for someone who just wants to Get Stuff Done.
cHao