Click here to Skip to main content
15,904,155 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have to insert rows to multiple databases using linq
but after submit the first db i can't insert the row to another db
I want to make the dbs have the same data with same ids

What I have tried:

C#
City TheRec1 = new City();
TheRec1.Name = c.Name;

DB1.Cities.InsertOnSubmit(TheRec1);
DB1.SubmitChanges();
DB2.Cities.InsertOnSubmit(TheRec1);//I get error here
DB2.SubmitChanges();
DB3.Cities.InsertOnSubmit(TheRec1);
DB3.SubmitChanges();
DB4.Cities.InsertOnSubmit(TheRec1);
DB4.SubmitChanges();
DB5.Cities.InsertOnSubmit(TheRec1);
DB5.SubmitChanges();
Posted
Updated 29-Aug-16 9:13am
Comments
Afzaal Ahmad Zeeshan 29-Aug-16 15:41pm    
You get, which error? What is the type of the error, message etc.

Basically it can be saved to multiple databases, tables or even networks. But the error would hold specific information.

1 solution

You cannot attach a single entity object to multiple contexts and have all those contexts cooperate with each other. They don't know about each other at all.

The only way to make this work is to have one copy of each entity object for each context. In your example, you need five copies of your "TheRec1" object, one for each context that is working with each of your databases.
 
Share this answer
 
Comments
M. Daban 29-Aug-16 15:35pm    
that is hard, because I have another tables which are have too many properties. that will make the code very long

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900