eba
eba

Reputation: 673

LINQ to SQL - two same databases

I have two SQL servers with the same database. Now I want to copy some data from the first to the second. I created two LINQ to SQL classes, but when I write the query I get an error because of name collisions. How can I avoid this?

Upvotes: 1

Views: 62

Answers (1)

Marc Gravell
Marc Gravell

Reputation: 1062600

If the schema is the same (like it sounds), you should be able to use the same model, but just use different connection-strings / connections to initialize two data-context instances. The problem however, is likely to be detaching objects from one model to pass to the other, and all the primary key goodness. In essence, I would recommend copying the objects and passing different objects with different keys to the second model.

Also, if the volume is very high, you might find SqlBulkCopy coupled to SqlDataReader useful; but that doesn't use LINQ-to-SQL at all.

Upvotes: 2

Related Questions