views:

51

answers:

2

Simple question, hopefully with a simple answer. I was under the impression I should create my tables and then use the map files to map my POCO classes to the database objects. After following some tutorials, I have this code in my Test SetUp:

 new SchemaExport(_configuration).Execute(false, true, false, false);

Which, obviously, create the table structure as defined in the mappings, so I'm confused.

+1  A: 

It is better to have only one place to change, in your case you make changes in your classes and your db is automagically updated - do you expect anything better?

Sometimes you write new code for existing database, so you have to create (or have) database first, then need to prepare mappings manually.

EDIT: I am using Fluent NHibernate, so this can be done fully automatically, not sure in different environments.

twk
+1  A: 

You need the mapping files for SchemaExport.

Ideally you write / design your classes first, write the mapping files afterwards. When writing mapping files, you are designing the database tables at the same time. SchemaExport just creates the schema from the mapping files where all the information is usually available.

SchemaExport is highly recommendable, even if it is a bit "hidden" in the docs.

Stefan Steinegger