CodeSmith Community
Your Code. Your Way. Faster!

CopyTo vs Clone vs Copy Question

Latest post 01-25-2007 12:01 PM by GASTAN. 3 replies.
  • 10-20-2006 2:15 PM

    CopyTo vs Clone vs Copy Question

    Does one of these commands maintain the IsDirty, IsNew, IsDeleted collections when creating a second instance of a BusinessObject collection?

    Any and all help is most appreciated?

    • Post Points: 35
  • 10-20-2006 3:21 PM In reply to

    Re: CopyTo vs Clone vs Copy Question

    Looks like the entities Clone method is not persisting state.  It's resetting state by calling AcceptChanges().  So that it's a clone of the data but not of state.
    I'm not 100% positive on best practices for this one.  I'll google around and maybe one of you that knows the answer could chime in as well.

     In the meantime, you can just use something like FindAll, which does not call Clone on the entity.

    TList<MyEntity> copiedList = list.FindAll(delegate(MyEntity entity)
    {
        return true;
    });
    

    - EDITED TO ADD: However it is still a reference to the entity in the original list, and not a copy of of the entity. 


    Robert Hinojosa
    -------------------------------------
    Member of the Codesmith Tools, .netTiers, teams
    http://www.nettiers.com
    -------------------------------------
    Filed under: ,
    • Post Points: 35
  • 10-20-2006 5:18 PM In reply to

    Re: CopyTo vs Clone vs Copy Question

    Unfortunately, this won't work either because it returns only a reference to the original list.  We really need to store a back up instance of the entity collection in case a user cancel's editing on a child form.  We need a way to get back to the previous instance to "rollback".  Therefore, we need a way to capture not only a data but also state. 

     Any information would be helpful.  Thanks for looking further into my issue.

    Rob

    • Post Points: 35
  • 01-25-2007 12:01 PM In reply to

    • GASTAN
    • Top 75 Contributor
    • Joined on 11-22-2006
    • Posts 53
    • Points 1,190

    Re: CopyTo vs Clone vs Copy Question

    I also do have problems when Clone() ing

    Items added to collections  do not get stored, even their state is Added :( 

    • Post Points: 5
Page 1 of 1 (4 items) | RSS
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems