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 1011041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T09:10:31+00:00 2026-05-16T09:10:31+00:00

Supposing the following entities : public class AppUser { public virtual int Id {

  • 0

Supposing the following entities :

public class AppUser
{
    public virtual int Id { get; set; }
    public virtual string Login { get; set; }
}

// Mapped as joined-subclass
public class Person : AppUser 
{
    public virtual int Age { get; set; }
}

If I create 1 AppUser, and save it like this

var user = new AppUser() { Login = "test" };
session.Save( user ); // let's say Id = 1

How can I cast/convert/”promote” it to a Person, keeping the same ID ?

Now, i’m stuck with a row in my AppUser table, with Id = N. How can I populate the Person table with the same Id ? I can’t delete the AppUser and recreate it as a Person, as AppUser may be referenced by foreign keys.

I could issue a “manual” SQL INSERT, but it’s kind of ugly…

This is definitively a NHibernate question. I understand that from an OOP point of view, this makes little sense, hence the absence of other tags than nhibernate.

  • 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-16T09:10:32+00:00Added an answer on May 16, 2026 at 9:10 am

    I don’t believe nHibernate is going to be able to solve this problem for you. nHibernate is dealing with your data as an object and, especially with joined-subclass I don’t believe there is anything built in that allows you to change the subclass type on the fly, or at least change the type and retain the original ID.

    I think your best bet is to write a stored procedure that, given an ID and a NEW type, removes all entries from subclass tables and adds a new entry to the correct subclass table.

    Once that proc runs, then reload the object in nHibernate (and make sure you have thrown away any cached data relating to it), it should now be of the correct type you want to work with, set its NEW properties and save it.

    That way you have a relatively generic stored proc that just changes your subclass types, but you dont need to add all the crazy logic to handle various properties on your subclasses.

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

Sidebar

Related Questions

Supposing the following situation: typedef struct rgb_t {float r,g,b} rbg_t; // a function for
Supposing I have a function with following signature: Foo[] getSomeFoos() { //return null ---
While doing the data/time parsing in c++ (converting a string in any format to
I heard a lot that data should be properly aligned in memory for better
My sheet already has data. Unfortunately, later I realized that all the values in
I was looking at open source ALM tools and discovered an interesting project called
Hallo Everyone, with the iOS 4, the iPhone is supporting Multitasking, what is very
Greg Young talks about avoiding getters and setters on domain objects when using Domain
I need to do mail processing where I manipulate the contents of the mail

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.