Custom EFDAL generator for nHydrate

Custom EFDAL generator for nHydrate

nHydrateis a model first ORM code generator on codeplex, and can be used to generate Entity Framework DAL layer. But unlike the designer in Visual Studio it is text based, but this is not a disadvantage as nHydrate offers greater features such as built in row auditing and incremental database management. As any development team knows version 1 of your application is easy, but version 2 is likely to have database schema changes. The incremental database management keeps a track of all SQL used to modify the database so you can migrate the schema changes to your production database with ease.

In the application I’m building the database connection string is only known at runtime, and in trying nHydrate I found the generated code did not support this for the audit system. I needed to make a change to the code generation to allow me to add my runtime connection string.

Also, in this application I want to use for the business layer, and want to use the CSLA code T4csla generatoron codeplex which uses T4 generation from the Entity Framework designer edmx file.  Now nHydrate does not have a edmx file because it does not need one. The EFDAL generator does generate the three csdl, ssdl and msl files, which Entity Framework generates from the edmx file.

So I have added a EFEDMX Generator Item to create this file using the same generators that produce the three files. Once you have edmx file you can right-click on the design surface when the file is open in Visual Studio and using the Add Generation Item to add the CSLA template. At present the and the resulting csla class files will be in the wrong class library – they’ll be sharing the same as the EFDAL code. I hope to resolve this later.

The attached Zip is self contained class libraries from 56617 on codeplex, the only changes I’ve made is to the links for the AssembyCommon.cs and the SNK files. Once built copy the EFDAL dll to your normal nHydrate install.

Edit: I didn’t anticipate what would happen to T4Csla’s properties when nHydrate was regenerated. The VSIX from T4Csla adds new properties to the graphic EF designer which are used to for the Csla class generation. Of course, when the edmx file is regenerated the values of those properties is lost. The obvious place for the Csla properties is within the nHydrate model, but that’s a lot of work and ongoing maintenance. I need to think of a better solution!

have fun! (1.48 mb)

Comments are closed.