Login

Username

Password





Register   Reset password

This is a read-only archive of the forum.

# sleuth 4/2/2005 3:07 PM
For the last week or so I have been thinking about a way to get a higher level of automation and strong typing within the “custom” Cuyahoga code base. In my experience as projects grow, methodologies that were manageable for 1 or 2 developers quickly become a nightmare for a team of developers.

I believe that one of the ways to allow continued development by multiple people and maintain a sustainable level of robustness is by automating the decoupled / weak type areas of the project. One of the biggest decoupled areas that I see is the relationship of the database to the mapping files to the Domain / state objects.

Thinking about this process it seemed to me that you would need to decide what the “master” would be when starting the generation process. To me it seemed natural that the database would fulfill this role; although I have talked to developers that consider the mapping files as the “master”. The best free Code Generator that I could find that supported NHibernate and several databases (PostgreSQL for me) was MyGeneration (http://www.mygenerationsoftware.com). Using this tool I pointed the NHibernate template at the existing PostgreSQL Cuyahoga schema and generated C# classes and NHibernate mapping files for the Cuyahoga core. The C# files and mapping files were very (if you squint you can see the same pattern) close to the existing Cuyahoga objects. The main difference that I noticed was that the original Cuyahoga files had a couple extra properties (usually an added array or list such as IList _childNodes) and code to maintain these extra properties.

Should the template be able to maintain this relationship? I would think that any one to many foreign key relationships could be generated as a List / array / collection with an associated class property?

My thought was that if we separated and structured the “custom code base” to enable generated code to propagate database changes then we could make much more rapid modifications with a higher level stability; allowing the compiler to catch many more bugs. For instance if I wanted to add a new column to the node table then I would just add it to the existing database schema, regenerate the mapping files and C# classes and change the code in the area that specifically dealt with using the new object properties. It is my assumption that we could find or make templates that generated database install scripts from the new mapping files.

While I am on the subject of strong typing; would it be overkill to generate a strong typed object from the web.config?

What would be the best way to strong type these kinds of statements:

(CoreRepository)HttpContext.Current.Items["CoreRepository"]

Context.Request.QueryString["ShortDescription"]

Place all of the “Name” strings in a public const area?
# martijnb 4/3/2005 2:01 PM
I'm very positive towards automating parts of the coding process, but definately not with the database schema as master. This is to some extent a matter of personal preferences but I think a design has to start with the domain model (the entity classes). If possible, a database can be generated or updated from that model but not the other way around, because a relational model simply can't contain as much information (for example, inheritance) as the domain model.

Maybe we can use Mats Helanders ObjectMapper in the future. It looks very promising. Unfortunately, right now, the NHibernate support isn't complete yet and the UI is well, ehm, not so user friendly.
While I am on the subject of strong typing; would it be overkill to generate a strong typed object from the web.config?

If I'm not mistaken, .NET 2.0 has this built in, so I prefer to leave it this way and wait for 2.0.
What would be the best way to strong type these kinds of statements:

(CoreRepository)HttpContext.Current.Items["CoreRepository"]

Context.Request.QueryString["ShortDescription"]

Place all of the “Name” strings in a public const area?

I would store these only in constants if they are used all over the place which is not the case right now (correct me if I'm wrong).