Database Layer With Different Types Database

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I know this is a silly question, but I am looking for the best way.

I build a windows application with standard version and enterprise version.
Standard version use local SQL/Access as database. Enterprise version use
Centralized Web Service as Database. Which is the easiest way to handle this?
I have too many classes have data access.

I can create following classes, How could I use Interface or other ways to
call right DB?
class1
class1_db_sql
class1_db_access
class1_db_webservice
 
Bit weird to use multiple db formats but anyway...

I'd make an interface class then inherit from that and override dependant on
which db.

so say interface was called MyInterface

public class dbAccess : MyInterface //inherit interface

public class dbEnterprise : MyInterface //inherit interface


then when u wanna use the access one:

MyInterface m = new dbAccess();

or the enterprise one

MyInterface m = new dbEnterprise();

And that ofcourse can neatly be used with the factory pattern.

then ur code for your method calls for both enterprise and access versions
will not change.
 
Hi,

It sounds to me like you need a way of easily switching the data layer at compile-time, not runtime. In that case you can extend
Daniel's idea and add conditional compilation to choose the appropriate database at compile-time:

#define ENTERPRISE

using System;

static class DALFactory
{
static IDataAccessLayer Create()
{
#if ENTERPRISE
return new EnterpriseDAL();
#else
return new StandardDAL();
#endif
}
}

If you're using VS.NET then it's even easier. Don't use the #define directive, but instead create a new configuration for your
solution in the Configuration Manager, and define the symbols there. When you want to build for the enterprise select the new
ENTERPRISE configuration that you created from the dropdown (instead of RELEASE or DEBUG). If you want a standard build, just
choose RELEASE.

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top