views:

24

answers:

1

I have two different DataContexts (SQL Databases) that have the same data, just with slightly different naming:

DB1: Serialnumber Productnumber DB2: SerialNumber ProductNumber Result

So I want to be able to wrap these tables in a class that will let me get back the serial number and product number regardless of the DataContext that it is coming from. I've looked into DataTableMappings, but I really have no idea where to begin. I'd also like this to work via LINQ and direct SQL queries. Again, I'd like it to be as generic as possible so I can use the same LINQ queries for the two different contexts. What is it that I am looking for?

+1  A: 

As a start, you'd probably want to consider coding against interfaces with your business logic - that way you can pass in DB1 or DB2 objects as long as their classes implement the interfaces specified.

Frank Tzanabetis
This is what I'm asking how to do. I've tried a few ways, but none seem to give me all the results I want (mostly incompatibilities with LINQ).
MGSoto
Yes, i've been there (L2S is a pain to get to work with interfaces when property names differ from field names in the DB), but there are ways to make it work. Have a look at this, perhaps it might give you a few ideas - http://connect.microsoft.com/VisualStudio/feedback/details/526402/linq2sql-doesnt-like-it-when-you-wrap-column-properties-with-properties-in-an-interfacehttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/5691e0ad-ad67-47ea-ae2c-9432e4e4bd46
Frank Tzanabetis
Those links helped a lot, specifically the first one. Looks like it might be a little more trouble than it's worth, but it does look manageable. We have decided to take a different route on our project, but this is very valuable information. Thanks!
MGSoto
No probs. It might look like a bit of trouble, but i've using that approach for the last 2 years and it's (mostly) a pleasure to work with. Being able to use the same code on multiple tables with virtually the same structure with little effort gives me that warm, tingly feeling inside :)
Frank Tzanabetis