11

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?

Sergio Tapia
  • 40,006
  • 76
  • 183
  • 254
  • I have been working for a long timle in MVC and I still do it this way – Nealv Jul 28 '10 at 22:49
  • Seriously, this is the best, most accepted way? Seeing as 90% of the process is mechanic isn't there a tool to do this for you? – Sergio Tapia Jul 28 '10 at 22:51
  • Not that I have seen yet, maybe someone else did, hope they post it here then :) – Nealv Jul 28 '10 at 22:57
  • "Sans creating my own T4 template, is there a tool that will help me". There are other templating languages, and there may be a specific templating mechanism for this database work, but many developers simply write code generators for a problem like this. T4 is a code generation language. – Merlyn Morgan-Graham Aug 07 '10 at 22:23
  • Familiarize yourself with creating templates in which ever IDE you're using. There are many tools that will allow you to generate code as listed in some of the answers. It also helps to have a good IDE which helps you implement code, like IntelliJ, Eclipse & NetBeans. For Visual Studio you'll probably have to buy a good plugin like Resharper, but it is definately worth the cost. – Christo Aug 08 '10 at 14:37

6 Answers6

4

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.

Omar
  • 39,496
  • 45
  • 145
  • 213
2

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
  • 446
  • 4
  • 7
1

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.

Advantage of creating a generic repository vs. specific repository for each object?

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.

Community
  • 1
  • 1
davy
  • 4,474
  • 10
  • 48
  • 71
0

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
  • 3,004
  • 23
  • 29
0

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
  • 2,159
  • 1
  • 20
  • 28
-2

Create a framework!

Brian
  • 5,826
  • 11
  • 60
  • 82
  • 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 Aug 08 '10 at 14:38