0

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?

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

This post blog.codefluententities.com/2014/01/29/… show how to handle multiple databases with CodeFluent Entities.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.