Using LINQ to SQL with multiple databases

  • Thread starter Stuart Ferguson
  • Start date
S

Stuart Ferguson

I am working on a new project and hoping to use LINQ to SQL for the data
access but have come across the following issue.

I need to have my application access 3 databases with similar but not
the same table structure, for example

Database1 and Database 2 has a table called tblCustomer with 2 columns
CustomerKey and CustomerName

Database2 has a table called tblCustomer with 3 columns CustomerKey,
CustomerName and CustomerPostCode

I am looking for a solution that will allow me a query all three
databases without the need for 3 GetCustomerList functions as Database1
and Database2 could use the same function as are the same structure,
with an override function for database 3 to bring back the additional
field.

Is there a way i can declare a base datacontext class to handle Database
1 and 2 with an inherited version for Database 3.

Thanks In Advance

Stuart Ferguson
 
M

Mr. Arnold

Stuart said:
I am working on a new project and hoping to use LINQ to SQL for the data
access but have come across the following issue.

I need to have my application access 3 databases with similar but not
the same table structure, for example

Database1 and Database 2 has a table called tblCustomer with 2 columns
CustomerKey and CustomerName

Database2 has a table called tblCustomer with 3 columns CustomerKey,
CustomerName and CustomerPostCode

I am looking for a solution that will allow me a query all three
databases without the need for 3 GetCustomerList functions as Database1
and Database2 could use the same function as are the same structure,
with an override function for database 3 to bring back the additional
field.

Is there a way i can declare a base datacontext class to handle Database
1 and 2 with an inherited version for Database 3.

Thanks In Advance

If you're talking about going to the designer and start changing code, I
wouldn't advise it.

You should just add the 3 databases with the tables needed to the
project using Linq_2-SQL and just query across databases
with one Linq query statement against 3 contexts.

If you don't want to do that, then use ADO.NET, SQL Command object, and
a sproc.

Your other option would be to use ADO.Entity Framework, possibly using
Entity-SQL.
 

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

Top