Search code examples
.netormsubsonicsubsonic3data-access-layer

One Set of POCO classes with interchangeable databases


I have an application that uses a set of tables to store data.

Based on client requirements they can use either Oracle or SQL Server.

Is there a way I can create all the POCO classes that represent the tables and then somehow when the Save() method is called it updates the correct database?

So for example:

Person p = new Person;
p.Name = "John";
p.Save(); //This saves it to the database but somehow it knows to use a Oracle connection or SQL Connection

UPDATE: I have just read that the Entity Framework 4 supports multiple databases but previous versions there was a lot of bloat with it so I'm a bit put off by it and not sure whether this would provide me what I want.


Solution

  • If I have this kind of requirement I will use some ORM which works with POCOs (preferably using Repository Pattern like Subsonic). Then you can just change connection in configuration file or use IOC to init the ORM with correct context.