문제

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.

도움이 되었습니까?

해결책 2

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

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top