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

  • Home
  • SEARCH
  • 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 324841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:09:40+00:00 2026-05-12T09:09:40+00:00

How can I make such behaviuor in NHibernate: There is an entity called User

  • 0

How can I make such behaviuor in NHibernate:

There is an entity called User in my domain

// I ommit mapping attributes
public class User
{
  int Id {get; set;}
  int pId {get; set;}
  //....other props, such as Login, Name, email...
}

I need to make full copy of it, when updating. pId must be set to original Id. Old entity must be untouched.

So this must be like some versioning system, where pId – is immutable identity, and Id – is like version. I`ve tried to use Version mapping attribute, but it just updates Version field, withou recreating full entity. What approach will be better?

  • 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. Editorial Team
    Editorial Team
    2026-05-12T09:09:41+00:00Added an answer on May 12, 2026 at 9:09 am

    I wrote a versioning system for our application. I split the versioned object into two classes, one that represents the whole object and one for its versions.

    In our software, the versioning is part of the business logic. The application provides access to the history and the user has some control over the versioning.

    A new version is therefore created in memory. You need to perform a deep-copy. You could implement this by implementing an interface in the root entity and all its children. This interface provides a method DeepCopy which is recursively called through the object graph.

    There is also a protected MemberwiseCopy method in object, which could be helpful. It does not a deep copy.

    We didn’t want the pain to maintain the code which copies each single property. So we are using serialization to copy an object graph in memory:

    public static T CopyDataContract<T>(T obj)
    {
        NetDataContractSerializer serializer = new NetDataContractSerializer();
        using (MemoryStream stream = new MemoryStream())
        {
            serializer.Serialize(stream, obj);
            stream.Position = 0;
            return (T)serializer.Deserialize(stream);
        }
    }
    

    Additionally, we have methods in the entities which reset the ids and do some other cleanup. This is also done recursively though the object graph.

    For now, it works fine. In the future we probably need to refactor it to the interface implementation, which is a bit cleaner.

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

Sidebar

Related Questions

How can I make such layout? Header should not scrolls and should be always
In the following, how can I make it such that the program uses the
In the following case, how can I make it such that the text generated
We're looking at patterns such as MVP that can help make us seperate UI
I have a class that contains multiple user objects and as such has an
Is there an OS or user-account level modification for windows 7 that I can
I can make a DAO recordset in VB6/Access do anything - add data, clean
I can make Firefox not display the ugly dotted focus outlines on links with
How can make a link within a facebox window that redirects it to another
I can make a single row IKImageBrowserView by setting the [imageBrowser setContentResizingMask:NSViewWidthSizable]; but in

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.