Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 153735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:51:13+00:00 2026-05-11T09:51:13+00:00

I want to create previous versions so a user can undo changes made and

  • 0

I want to create ‘previous versions’ so a user can undo changes made and roll back to a previous version.

I’ve got a manager object with various properties and a collection of managed staff. this relates to two tables in the database with staff linked to the manager by a foreign key.

What i’d like to do is duplicate the manager and all his staff and save it back to the database as a new entry in the manager table and a series of new entries in the staff table that our related to the new manager.

I’m using nhibernate and wondered if there was a clever way of doing it with this.

The only way i can think of doing this is manually:

manager old = getManager(); // get the original for copying   manager newManager = new manager(); // create a blank object newManager .name = old.name //give the new manager the old one's props;  //cycle through the staff duplicate and add to new managers staff collection foreach(staff s in old.staffCollection) {   staff newStaff = new staff();   newstaff.name = s.name;   newManager.staffCollection.Add(newstaff);  } 

the above example is not exactly how i’d do it but you get the idea i hope.

I’ve thought about using reflection to get the props instead of manually setting them but that’s about as clever as i’ve got.

is there a way in nhibernate to copy the object graph and persist it back as new entries?

or has anybody got any bright ideas??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T09:51:14+00:00Added an answer on May 11, 2026 at 9:51 am

    If you mark your Entities as Serializable you could do Binary Serialization.

       public static MemoryStream Serialize(object data)     {          MemoryStream streamMemory = new MemoryStream();         BinaryFormatter formatter = new BinaryFormatter();         formatter.AssemblyFormat = FormatterAssemblyStyle.Simple;          formatter.Serialize(streamMemory, data);          return streamMemory;     }     public static Object Deserialize(MemoryStream stream)     {          BinaryFormatter formatter = new BinaryFormatter();         formatter.AssemblyFormat = FormatterAssemblyStyle.Simple;         return formatter.Deserialize(stream);      } 

    Essentially you would call the Serialize then the DeSerialize method this will give you a deep copy of your graph, then you’d have to update any ID’s you might have.

    Word of caution, I’m not sure how this will play with nHibernates lazy loading functionality. I’ve done this a lot but not with objects I pull from nHibernate. Also don’t forget to put Serializable on your objects.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 118k
  • Answers 118k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Cache is an important part or a web app, but… May 11, 2026 at 11:38 pm
  • Editorial Team
    Editorial Team added an answer For the Namespace - I would focus on the standard… May 11, 2026 at 11:38 pm
  • Editorial Team
    Editorial Team added an answer I've had similar problems with an application that I started… May 11, 2026 at 11:38 pm

Related Questions

I have a MS Office COM addin written in C# (Visual Studio 2005) and
My research and experiments haven't yielded an answer yet, so I am hoping for
I started using bazaar after a long camping in the svn field. I had
I want to redirect from an action in one controller to an action in

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.