views:

130

answers:

3

Hi, Is there any other method than nHibernate by wich we can generate db schema from class definition? My classes arn't that complex etc (few one-to-many relations). However I would like to just be able to save my objects in db and recreate schema if needed. I am stuck with .NET 2.0. I am not that particular about performance for this project, I am just lazy to create tables and write save/load code and deel with nHibernate xml.

Thanks

+2  A: 

.NET classes are not compatible with a relational data model. That's why ORMs such as NHibernate exist. Without a mapping which describes the conversion of the model to relational tables you cannot create a DB schema. You could take a look at FluentNhibernate automapping feature. If you stick to the conventions it can create the database schema from .NET classes.

Darin Dimitrov
according to this http://stackoverflow.com/questions/428151/fluent-nhibernate-api-and-net-2-0.NET 3.5 is required for fluent nhibernate.
Niran
@Niran, that's correct, I've missed this requirement.
Darin Dimitrov
This isn't correct. Automapping allows you to use conventions to avoid creating mapping files, it has nothing to do with schema generation.
Jamie Ide
A: 

Yes, ther are other ways. THis is called "programming" - you may have heard of that. Basically, it is possible to write your own database generator. Been there, done that, long before nhibernate had that functionality (or, actually, even existed).

Sit down, write your own database generator.

TomTom
A: 

NHibernate can do this. The relevant classes -- SchemaExport and SchemaUpdate -- are in the NHibernate.Tool.hbm2ddl namespace. Here's one example.

Jamie Ide