Fluent NHibernate automatically deletes data Fluent NHibernate automatically deletes data postgresql postgresql

Fluent NHibernate automatically deletes data


I'd say that the problem lies here:

.ExposeConfiguration(cfg => new SchemaExport(cfg).Create(true,true))

It seems you're exporting the schema every time when building the session factory. Now I'm not 100% sure (I have never used code-first to generate the tables, only mapped to the existing database I created beforehand), but I bet that the export overwrites what you already have (drop & recreate or whatever).

Here someone had a similar problem with SQLite file getting overwritten when exporting schema with Fluent NHibernate, so I'd say you have to be careful when and how you (re)create the database :)