Question

I need to create an exact copy of data stored within a database. We're using the entity framework code frist so I'm trying to figure out how to make this happen. The object structure is fairly complex and I don't want to manually write all of the code to make a new object. This would likely become a maintenance problem in the future.

My question is this, is there a way to load data using entity framework and then save back the same data into new records?

Now, before you tell me that data replication is bad and I shouldn't be doing this, I should explain myself. Our data can be either live data for our end users, or it can be templates used to create new live data. It's this process of creating the new live data that I'm talking about here.

I've seen several solutions that accomplish this via serialization, but this generally seems like a hack. I'm not completely opposed to the idea, but would prefer a more EF friendly approach.

Any help would be much appreciated.

Was it helpful?

Solution 2

I ended up solving this problem by using the Copyable project by Håvard Stranden.

OTHER TIPS

The friendly approach is serialization. If you think it is a hack you can always write all code yourselves.

Deep clone or copying from prototype is almost always handled by serialization.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top