Click here to Skip to main content
Licence Ms-PL
First Posted 18 Feb 2011
Views 5,005
Bookmarked 11 times

nHydrate Generator Library

By | 18 Feb 2011 | Article
How to use the nHydrate Generator Library.
 
Part of The SQL Zone sponsored by
See Also

Introduction

The nHydrate ORM platform is a useful tool for creating data frameworks, inversion of control, and performing other programmatic tasks. However, many generators have been added over the last year and the UI itself has become confusing. At last count, there were 14 different generators. Most people only use one or two, so the rest are just clouding up the generative UI.

To address this issue, a Generator Library has been created. Now when you install nHydrate, there are no generators installed with it. The first time you create or open a model, the library dialog will pop-up allowing you to select a package for download. At present, there is an Entity Framework Data Access Layer (DAL), an ADO.NET DAL, and various other permutations of these and other components. A package contains one or more generators. For example, the ADO.NET DAL package has two assemblies in it. One that generates the DAL and another that generates the database installation/tracking project. These work in tandem to create a matching database and API based on an nHydrate model.

There are more complicated packages of course that include Inversion of Control generators and such, but this simple example demonstrates why packages are downloaded instead of individual generators. Some packages are complex in that there are number dependencies between generated projects so downloading all of them as a unit makes sense.

When you first open a model, you see the Generator Library screen as shown above. The first page shows you the packages available for install. If you already have all the components for a package and they are up to date, the package will not appear in the list. The second page is a list of all installed generators. There can be multiple generators in one package. So after you install a package, there may be many items in your installed list. When updating generators, you will need to close and re-open Visual Studio as the assemblies are locked on disk. You will be prompted to do this if it is necessary. When downloading a new package, this step will not be necessary of course.

Once you download a package, it will be removed from the displayed list. Now you can close the dialog and start generating. I have downloaded the ADO.NET package in this example. After creating my model, I choose the Tools|Generate menu. This will display a generate dialog that prompts me for which projects I wish to create. Notice that there are two generator templates in this dialog now. The package I downloaded had two items in it: the DAL and the database installer. I will use both of these projects as my API and database must be kept in sync.

After I generate, you can see the new projects in my solution. As I change my model and re-generate, these two projects will always be in sync. As I add/remove/rename tables, columns, etc., both my API and database installer will always match. This is the beauty of model driven development.

There are many more generator templates that can be downloaded and you can write your own generators that create code based on a model as well. You can see that this is a simple way to defining a development model and using predefined templates to create code. Another bonus is that all generated projects are based on the same model so when you re-generate, your entire solution/platform is updated and in sync.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)

About the Author

Christopher R Davis

Architect
Jackson Healthcare Solutions
United States United States

Member

Follow on Twitter Follow on Twitter
I currently design job boards and create developer tools. I have been working with technology since the VIC 20. I am currently co-authoring the nHydrate code generator (and other projects) with Michael Knight in Atlanta, GA. We have built a faceted navigation engine that allows you to list any set of objects (cars, jobs, apartments, etc) on a website that gives users the click-through experience. My goal is no more advanced search pages.
 
I use nHydrate at my day job every day and use it manage a half dozen production websites. It has greatly reduced the staff needed. The quality of code is greatly enhanced since I do not hand code all of the backend.
 
In addition to these projects, I founded Gravitybox Software years ago and is quietly fading away now. I concentrate my time on code generation and faceted navigation.
 
Check out the current nHydrate site on Codeplex. http://nhydrate.codeplex.com
 


My LinkedIn Profile

LinkedIn nHydrate Group

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120517.1 | Last Updated 18 Feb 2011
Article Copyright 2011 by Christopher R Davis
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid