Click here to Skip to main content
13,087,797 members (81,231 online)
Rate this:
Please Sign up or sign in to vote.
See more:
if i build project using Nhibernate .net then after completing project can i switch one database server to another database server only by changing single configuration file ?

if it is possible then how can i do by Nghibernae .NET.

i am developing project but i want to use same project in multiple database server.. is possible in java hibernate but i want to use .NET platform. so is it possible in Nhibernate .NET. ?
Posted 27-Dec-12 23:27pm
Updated 28-Dec-12 1:30am
Oleksandr Kulchytskyi 28-Dec-12 5:33am
So what do you meand in term of "multiple database server"?
Is it the same server architecture , but in differ location???
Or you mean various DB servers??
SmartCodeproject 28-Dec-12 5:47am
i mean various DB server...
like oracle , MSsql server, mysql.
i want to use same project in these 3 database server

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

thus, based on the latest updates from U.
My approach lies in next.
You might to create generic repository interface and leverage it for basic CRUD operation , also you can leverage it with conjunction of UnityOfWork pattern(for example to commit all affected entities)....

After that you might implement specific entity repositories by inherits that generic repo interface and adjust each type of repo for concrete Database architecture.
so, for example in a result you will have
DepartmentRepoSqlServer,DepartmentRepoOracle... and so on.
SmartCodeproject 28-Dec-12 6:24am
thanks for answer...

i didn't understand it...
i know java hibernate in this we create hibernate mapping file that is xml file and also create single hibernate configuration file that is also xml.. in this we can create hibernate mapping xml file in such a way that support different database server like orace and mySql and sqlServer.. then if i want to switch database server from oracle to sqlServer i have to change only hibernate configuration xml file and only have to chance connection class like that.. i dont need to change hibernate mapping class.. in such a way i can switch one database server to another database server to changer few lines with no problem.

if such a approach is present in Nhibernate .NET. that only i can changer only database configuration like connection string and connection class.. and can i switch MS Sql to my Sql to change few lines in hibernate configuration file ?
Oleksandr Kulchytskyi 28-Dec-12 6:28am
Ohhh , sorry for my inattentiveness. Now i have caught what you mean..
Yep of course this things are still relevant for NHibernate.
SmartCodeproject 28-Dec-12 6:55am
again i didnt understand u.
it is possible in java hibernate..
how can i do it in Nhibernate .NET ?
or it is not possible ?
Oleksandr Kulchytskyi 28-Dec-12 7:56am
Sorry for so late response....
But if be honest, in my turn, i do not understand U..
What did you expect? If you are expected that i will write a whole explanation turtorial about implementing the same func like Java Hibernate but in consideration of NHibernate...
Do you know how much time it can takes?
I have shared to you from my Skydrive a link to a book, please read it!!!!4507&authkey=!AKPW5f3sM0xm0ig
SmartCodeproject 28-Dec-12 9:43am
sorry for my language u don't understand.
but i want to know answer in the form or only (YES OR NO)

1) i write application using NHibernate with configuration MS Sql server.
2) application is completed.

now i want to run this application on MySql database server.

is it possible without recompile application

Oleksandr Kulchytskyi 28-Dec-12 9:47am
1) i write application using NHibernate with configuration MS Sql server.-
In which form this configuration is persisted? in case of FLUENT API, my answer is NO, otherwise (in case of xml config), - YES.

NHibernate is some aspect is a replication (porting code from JAVA platform to C#) + some complementary changes have been added (such as LINQ - which is not characteristic of JAVA)
SmartCodeproject 28-Dec-12 10:22am
Thanks :) :) :) :)
this one i wanted
Thanks again
:) :) :) :)
SmartCodeproject 28-Dec-12 9:48am
thanks for book
Oleksandr Kulchytskyi 28-Dec-12 9:50am
You are welcome.
Oleksandr Kulchytskyi 28-Dec-12 6:24am
Furthermore, in you injected in your solution such things as DI, and IoC,
you can achive functionality of replacing of usage differ DB servers on runtime , for example using config files.
SmartCodeproject 28-Dec-12 6:31am
can i have some example of config files with is using different DB server.. and i am not using IoC in my solution.. i don't want to use concept of AOP in my solution

SmartCodeproject 28-Dec-12 6:34am
can i have example such a hibernate config file which is using different DB server in same project.
i dont want to user IoC such a concept in my project and not using AOP.

SmartCodeproject 28-Dec-12 6:25am
if this is possible then tell me few steps how can i do it. or tell me some tutorial how can i do it ?


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.170813.1 | Last Updated 28 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100