views:

198

answers:

2

I was wondering what would be the best way to create LINQ-to-SQL classes to deal with a given entity which is present in 10 different data sources. Let's say I've got the same database in 10 different countries, each of them with a Customers table, and my goal is to access all of them programatically. Should I either create:

  1. a single ADO.NET Data Model then try to combine everything there;

  2. as many LINQ-to-SQL classes as existing data sources;

  3. a single LINQ-to-SQL class mapping a single data source, then manipulating its connection string.

Your feedback will be really appreciated. Thanks everyone for your comments!

+2  A: 

Well, if they truly are the same, I would just go with Option 3 -- use a different connection string when connecting to each of the data sources.

Dave Markle
Agreed- as they are the same database but different location they should have exactly the same schema. You can easily change this by passing a different connection to the DataContext.
RichardOD
Yeah, you just have to be careful that you don't try to reuse objects across DataContexts without attaching and detaching them appropriately.
Dave Markle
Thanks much, it helped a lot!
Nano Taboada
+1  A: 

The first and the third options are practically equal, the thing that matters is your preference.
If you don't have schemas with the same name in all your data sources, you will have to make some manual changes to the model in any of these two cases.
In EF you'll have to remove the Schema attribute using XML Editor.
In LINQ to SQL, you'll have to remove the schema name prefix from the Source property in designer.

Devart
Thanks a lot Devart!
Nano Taboada