c# - How to deep clone objects containing an IList property using AutoMapper -
I am trying to clone the following squares with the automaker:
< Code> public class main data {public key data () {description = new list & lt; Expansion & gt; (); } Public Entity ID {Receipt; Private set; } Public Date Time Last Update {Receive; Private set; } Public IList & lt; Expansion & gt; Details {Receive; Private set; } Public Entprop 1 {Get; Set; } Public int prop2 {get; Set; } Public Zero AddDetail (Detail Details) {Details. Add (details); } Public Zonal Offices (Details in detail) {Details. Remove (extension); } Public Main Data Clone () {Mapper.Reset (); Mapper.CreatMap & lt; Menadata, menadata & gt; (). For Member (D => D.D., O = & gt; O. Anvoir ()); // mapper Createmap & lt; Expansion, expansion & gt; (). ForMember (d => DID, O = & gt; O. unknown ()); // New newData = new main data (deleted); Mapper Map (this, new medida); NewMainData.Details = this.Details.Select (item => item.clone ()). ToList (); // added the new MyDATA back; }} Public class extension {public id id (get; private set;} public string name {get} set;} public double area {get; set;} public double height {get; set;} public extension clone () / / ADEDED {Mapper} Creatives(). ForMember (d => DID, O = & gt; O. unknown ()); var newDetail = new extension ( ); Mapper map (this, new delay); new return;}}
The clone
method for the main code properties works fine, But only the shallow copy of the details list seems to have occurred, I have tried to add the . (D => D. Description, O = & gt; O for the Mail ())
But this does not copy the details list at all. How can I get the list list as a deep clone i.e., so I can eliminate completely independent objects, including all the items in the entire list ?
UPDATE: I need to leave the ID as property I am using these objects with NHibernate, so it is not certain that the serialized solution will do this.
UPDATE2: It also works to clone ILIS to modify the code given above because I think NHibernate thinks that it has already been saved, Can exclude properties
var = a solution with new main data () is; Clone Injectoft (main data); // Main data is the main data of your source. description. Asperaille For all (expansion => {var = DC = new extension (); DC (inclusive) from injection; clone.edit (DC);});
Property sets with private sessions are not set, (seems appropriate)
Good luck;)
EDIT: I did a better solution
Comments
Post a Comment