Reputation: 34325
I need to transfer data from one DB to another. The destination DB contains a much smaller amount of data than the source, and each table is only a subset of the source table's columns. I just created the destination DBML, and I'm rightly getting a compilation error because the L2S data type (in the destination DBML) is the same as the L2S data type in the source DBML.
Is there a way to share these types between data contexts? If not, is there a way to cast the source type as the destination type so I don't have to create mappers to map each source type to the destination type before saving to the destination DB?
To be clear, in the source DBML, I'm only including the necessary columns. That's why the source and destination types are exactly the same, but they belong to their own DBMLs.
This exact same table is in both DBMLs:
This question has been a struggle to articulate correctly. Another way to ask this would be: "Can I get the data from the source table, and save it to the destination DB, using just one type from the source DBML?"
Upvotes: 0
Views: 216
Reputation: 15901
As @David suggested create DBML in different namespaces and then use Automapper or write some code that generates the mapping (it's really easy given your requirements).
Is there a way to share these types between data contexts?
No.
If not, is there a way to cast the source type as the destination type so I don't have to create mappers to map each source type to the destination type before saving to the destination DB?
You have to create mappings - however, it's really easy (properties have same names, types, etc.). I even think it would be easier without Linq2Sql or any other ORM. IMHO you should drop all constraints, FKs, etc., copy data on SQL Command level (generate this code yourself) and then recreate all constraints.
Upvotes: 2