Click here to Skip to main content
15,886,199 members
Articles / Web Development / ASP.NET

nHydrate Generator Library

Rate me:
Please Sign up or sign in to vote.
4.00/5 (1 vote)
18 Feb 2011Ms-PL3 min read 14.5K   14  
How to use the nHydrate Generator Library.

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.

Image 1

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.

Image 2

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.

Image 3

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.

Image 4

License

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



Comments and Discussions

 
-- There are no messages in this forum --