0

I am new to NHibernate and was thinking to use it in a project which could support different database like (Oracle, MySQL, SQl Server, DB2 etc..) as this product might be shipped to different clients who could use different datbases as per their choice. However schema of different database would remain same.

As we know that NHIbernate provides out of box support to many databases, i have below doubts

1) Do we need to specifically install the individual database drivers or they come with NHIbernate setup? I could not find any drivers with the NHibernate installation files

2) Is it possible that by only changing the configuration settings etc my application can talk to different databases? i.e no code change apart from config settings would be required if code is sent to client who might be using any one of oracle/DB2/SqlServer database etc ?

Sarvesh
  • 269
  • 1
  • 2
  • 10
  • look at the classes in the `NHibernate.Dialect` and `NHibernate.Driver` namespaces. Also see http://nhforge.org/doc/nh/en/index.html#configuration-optional-dialects. It works "out of the box" because you don't have to write any code to make it work. You obviously have to have the appropriate ADO.NET connection classes (a.k.a. drivers) referenced. Provided that those classes are available, NHibernate will be able to use them. – Daniel Schilling Aug 28 '13 at 04:48

1 Answers1

0

Answering your questions:

1) No, NHibernate does not ship drivers. You have to look for them elsewhere. I, for example, use Npgsql with PostgreSQL.

2) It is very possible by changing your driver and your connection string to start using a different database without major problems (also by avoiding db specific mappings such as sequences or identity for id generation). I have migrated from SQL Server to PostgreSQL very recently; just so you have a notion of how well it went, the migrated product was querying over 70 tables with the HQL, Criteria and Linq APIs of NHibernate and we only had a problem with the collations being different in both databases, which does not concern NHibernate at all. In my opinion, as long as you stick to NHibernate for querying, you'll be safe.

Since you're leaving the choice of the database to your client, I would recommend you list and recommend only a few select databases. Your clients just might run across a bad driver, for example.

Marcelo Zabani
  • 2,139
  • 19
  • 27
  • Just a query then why do we say that NHibernate out of box supports the above mentioned databases. It is said that EF out of box supports only SQl Server whereas NHibernate supports Db like Oracle, MySQL, SQl Server, DB2. Did i miss something. – Sarvesh Aug 26 '13 at 13:30
  • Drivers need to implement certain features specific to Entity Framework to work with it. NHibernate needs drivers to implement much more basic ADO.NET features. Both can work with many databases, but drivers have to be a little more "advanced" to work with Entity Framework. Check http://msdn.microsoft.com/en-us/data/dd363565.aspx for EF compatible drivers if you want. – Marcelo Zabani Aug 26 '13 at 13:35