D
DD
Begginig EF, and one simple operation I am trying to do...yet I can not do it
simply.
I have 2 DB on 2 different servers, trying to copy records from one table
(which has no references to other tables in the EF model) to the same table
in the second DB/second server.
What I can't figure out is how to do it (since there is no deep
copy/cloning)...this doesn't work:
Entities sourceContext = new
Entities(ConfigurationManager.ConnectionStrings["SourceEntities"].ConnectionString);
Entities destinationContext = new
Entities(ConfigurationManager.ConnectionStrings["DestinationEntities"].ConnectionString);
IQueryable<TABLE1> tmpRecords = from records in sourceContext.TABLE1
select records;
List<TABLE1> recordList = tmpRecords.ToList();
foreach (TABLE1 record in recordsList)
destinationContext.AddToTABLE1(record);
Exception thrown is "The object cannot be added to the ObjectStateManager
because it already has an EntityKey. Use ObjectContext.Attach to attach an
object that has an existing key."
So my question is, what to do for this code to work? Or how to do it in
another simple way please?
Thanks in advance
simply.
I have 2 DB on 2 different servers, trying to copy records from one table
(which has no references to other tables in the EF model) to the same table
in the second DB/second server.
What I can't figure out is how to do it (since there is no deep
copy/cloning)...this doesn't work:
Entities sourceContext = new
Entities(ConfigurationManager.ConnectionStrings["SourceEntities"].ConnectionString);
Entities destinationContext = new
Entities(ConfigurationManager.ConnectionStrings["DestinationEntities"].ConnectionString);
IQueryable<TABLE1> tmpRecords = from records in sourceContext.TABLE1
select records;
List<TABLE1> recordList = tmpRecords.ToList();
foreach (TABLE1 record in recordsList)
destinationContext.AddToTABLE1(record);
Exception thrown is "The object cannot be added to the ObjectStateManager
because it already has an EntityKey. Use ObjectContext.Attach to attach an
object that has an existing key."
So my question is, what to do for this code to work? Or how to do it in
another simple way please?
Thanks in advance