views:

182

answers:

3

I've dug around through previously asked questions and have had no luck finding a duplicate. I would love to generate basic entity classes in .Net from a DB2 schema (using the iSeries OLEDB provider). Is there any simple way to do this? I've looked into MyGeneration and CodeSmith and it just seems like there must be an easier way.

Thanks in advance.

EDIT I'm taking the iSeries tag off of this in hopes that it will de-scarify the question a bit. Anyone have anything that they've used against any ADO.Net or OLEDB provider? I think I could adapt it to work with iSeries.

EDIT #2 Adding the iSeries tag back on and will accept my own answer in a couple of days, hopefully this will help someone in the future. +1 to responders, thanks.

+1  A: 

This is perhaps a little long winded, but one way is to reverse engineer the schema into an Object Role Modelling diagram using the NORMA VS plug in and then generate your .NET classes via the PLiX generator which comes with the plug in.

You may find the resulting classes are decorated with extra members which you may not need (they are coded so they can be used in a component model context if required) but you can strip these extra artefacts easily enough.

AdamRalph
Thanks for your reply.
AJ
+1  A: 

Have you tried Jeeves? It's a template-driven code generator written in Perl.

With Jeeves you can modify the specification parser and the templates separately, and inject Perl commands into the template.

I didn't do exactly what you want to do, but what I did was the following:

1) Used Jeeves' as-distributed OO parser, and created my object definitions in a specification file, which is in a format that this parser could read. 2) I coded the template to consume the abstract syntax tree that the OO parser generated from my specification file. 3) This in turn generates a code generator in Perl. I called this code generator as a pre-buld event (in VS 2005) and the generated code was compiled right then and there.

You'll have to build the template you want (and probably the spec parser) but once you do that you can output exactly what you want without a lot of extra overhead.

John at CashCommons
Thanks for your reply.
AJ
A: 

After more research, I decided to write the code generator myself. Part of the reason I asked was because the iSeries provider for .Net isn't very robust, so there's no given way to enumerate schema information. However, after finding this question, I was able to do it using simple inline SQL like this:

//Enumerate schema tables (excludes views)
select table_name from qsys2.tables where table_schema = 'schema_name' and table_type = 'BASE TABLE'

//Enumerate table columns
select * from qsys2.columns where table_schema = 'schema_name' and table_name = 'table_name' order by ordinal_position;

Maybe this will help someone in the future.

AJ
This might produce the schema data, but how does it produce C# class definintions? Wouldn't you also want to generate get and put metods to fetch rows to/from the database?
Ira Baxter