views:

30

answers:

2

I'm trying to get into using Fluent NHibernate, and I have a couple questions. I'm finding the documentation to be lacking.

  1. I understand that Fluent NHibernate / NHibernate allows you to auto-generate a database schema. Do people usually only do this for Test/Dev databases? Or is that OK to do for a production database? If it's ok for production, how do you make sure that you're not blowing away production data every time you run your app?

  2. Once the database schema is already created, and you have production data, when new tables/columns/etc. need to be added to the Test and/or Production database, do people allow NHibernate to do this, or should this be done manually?

  3. Is there any REALLY GOOD documentation on Fluent NHibernate? (Please don't point me to the wiki because in following along with the "Your first project" code building it myself, I was getting run-time errors because they forget to tell you to add a reference. Not cool.)

Thanks, Andy

+1  A: 

I don't use Fluent, but I can help with classic NHibernate.

  1. yes, the creation of the schema is very recommendable for production use (Schema Export). When you do this is up to you. For instance, you could create the database by an installer. You shouldn't drop existing databases, but this is a decision of you application.

  2. I don't understand this question. Do you mean you need to upgrade an existing database to a new database schema? This is unfortunately something you need to implement yourself. NH can't do much about this, because it is very specific to you data and the changes you made. There is also a Schema Update or something like this, which is not recommended for production use.

  3. I don't use Fluent, so I can't help here.

Stefan Steinegger
+2  A: 

I've been using Fluent NHibernate Automapping for a few months now. I'm by no means an expert, but can take a stab at your questions...

FNH Automapping does indeed create DB schemas from POCO classes, including lists of other objects (this was the reason I chose NHibernate in the first place).

When you change schemas, you have to rerun the automapping, which does drop the whole database, unfortunately. In my case, it's not a big problem because I'm importing existing binary data files, so I just have to re-import my data every time the schema changes. I've read that there's some data migration support available with NHibernate, but have no experience with this. (BTW, Subsonic will do data migration, but it's automapping functionality is far more rudimentary - at least it was when I evaluated it a few months ago)

FNH documentation is one of my pet peeves - they have not even added Intellisense help on the method names, etc. (But they get really huffy when you point that out - ask me how I know!) I've made a couple of edits to the wiki when I could, but there's so much more that could be done there. The best approach is to start with a working example (i.e. this one from Nikola Malovic, and post questions to the support form if (when!) you run into trouble. In general, I've found the FNH community pretty helpful, and have been able to work through all my difficulties. They've also fixed a couple of bugs I've found.

Overall, using FNH has been a huge win for my project - highly recommended!

Tom Bushell
Thank you for the tips. I'm giving up on Fluent NHibernate for now - far too frustrating, and as I gather, EF has reached a decent level of maturity.
Andy
Sorry to hear that. I too found it very frustrating at first, but am now really glad I stuck with it. I briefly looked into EF a few months ago, but word of mouth was bad, and I couldn't determine if it did automapping or not. Maybe the release of VS 2010 will fix the main problems people were reporting.
Tom Bushell

related questions