I need to copy data from one database to another using EF. For instance. I have the following table relationships: Forms-> FormVersions-> FormLayouts ... We have different forms in both databases, and we want to collect them into one database. Basically, I want to recursively load a Form object from one database and save it to another database with all its links. I also need to change the identifiers of the object and related objects, if there are objects with the same ID in the second database.
So far, I have the following code:
Form form = null;
using (var context = new FormEntities())
{
form = (from f in context.Forms
join fv in context.FormVersions on f.ID equals fv.FormID
where f.ID == 56
select f).First();
}
var context1 = new FormEntities("name=FormEntities1");
context1.AddObject("Forms", form);
context1.SaveChanges();
I get an error: "The EntityKey property can only be set when the current value of the property is null."
Will you help with the implementation?
source
share