Reputation: 1221
I want to give user choice to select database from multiple database(like SqlServer,Oracle,etc) list in the UI. Depending on the user selection, I want to connect to selected database.I can do this by creating interface and implementing that interface by separate class for each database.This approach is explained here
http://thetechstory.com/2012/09/29/connecting-multiple-databases-in-net-using-c-part-1-introduction/
I have also heard that it is possible by using NHibernate also. I don't know much about NHibernate. I have been searching through web.But I am not able to figure out which way is a better way to implement this scenario. Should I go for NHibernate or should code for separate database implementation?
Upvotes: 0
Views: 990
Reputation: 1175
Well it depends on what you want to do.
If you want to "code" everything, you can go for the "manual" implementation. But it implies that if someday you want to target another database provider, you will have to create the appropriate interface.
If you want to use an "out-of-the-box" product where this aspect is handle for you can go for NHibernate or other like (CodeFluent Entities).
Anyway there is no right or wrong answer, all depends on what you want to do.
Upvotes: 2
Reputation: 1469
NHibernate will require changes in cofig to connect to database. You might be able to do this at runtime (not sure about this).
Better approach would be if you create adapters for each type of database. See adapter pattern and user strategy pattern to choose one from list of databases.
[Update]
NHibernate is just an ORM, which will convert your table data into objects. You can use both the approaches at the same time.
Use adapter pattern for each database and in each adapter pattern use NHibernate to map objects to database and vice versa.
Upvotes: 0