NHibernate: initial amount of data

I use NHibernate as my ORM, and for single testing purposes I use sqlite as a replacement database.

To make unit test sense, I need to populate the tables. How to do it in NHibernate? Even though my module testing database is sqlite, I would prefer independent db scripts that let me do this.

Does Nhibernate support this out of the box? Or do I need to resort to using the NHibernate Save method for insertion?

P / S: part of an ORM or framework in another language (e.g. Symfony in PHP ), supports this via yml .

+4
source share
3 answers

AFAIK NHib does not provide you with the bulk import option ... you need to somehow create some objects and then call ISession.Save on them. If you go down this route, I recommend that you consider the Data Data Builder template .

Instead, you may have some objects serialized in XML and you will need to deserialize and save to customize your data, but I suspect XML will be tedious to support.

+1
source

Check out this blog post by ScotMuc and Autumn of Agile by Stephen Bohlen. They should point you in the right direction.

+1
source

I do not know a single tool that will do this for you, but it would be nice.

Your idea of ​​using a save method should work, and it will be as database independent as the rest of your application.

I have a console application that pretty much does this, so I can load the source data into a database for my main application to function.

0
source

All Articles