Free NHibernate: SchemaExport and SchemaUpdate

I need help with a problem in my application.

I created a project in Visual Studio, and I installed and configured Fluent NHibernate. I was able to configure everything correctly, and I was able to connect to my database.

I tried inserting a few rows into the table and everything was fine, but whenever I restarted my application, I noticed that the tables were deleted and re-created and all the data disappeared.

I solved this problem using:

.ExposeConfiguration(cfg => new SchemaUpdate(cfg).Execute(true, true)) 

instead:

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

Everything is still good, but now here is the problem. Let's say I have a Person.cs class with two fields: Id, Name. And let me want to add a new property Address . I add a property to my class and run my application. I am trying to add a few rows and check the database to see that a new column with the name "Addresses" was actually created, and zero values ​​were inserted for old records.

Now let me say that I changed my mind and decided to remove the new property address. I remove the property from the Person.cs class and run the application. I insert several records and check the database to see that the column address has not been deleted and is still in the table.

Why is this happening this way? Should the display configuration do everything for me? I expect unnecessary columns to be deleted in the database the same way they are created when new properties are added to my class and without losing my data. What should I do?

+4
source share
1 answer

SchemaExport / SchemaUpdate are not a migration infrastructure.

They only make sure that your domain can be used with a database and is useful during development (not in production).

+3
source

All Articles