简体   繁体   中英

NHibernate moving entity to different table

Using NHibernate I've got an account system set-up, with different kinds of accounts (different privileges, etc.)

What I want to do, and and cant figure out is: change one account type to a different account type.

Basic idea of the set-up below.

class Entity
{
  public int Id;
}

class UserAccount : Entity
{
  public string username;
  public string password;
  // additional account details...
}

class StudentAccount : UserAccount
{
  // student specifc information
}

class TeacherAccount : UserAccount
{
  // teacher specific information
}

In the example provided, I want to be able to promote a StudentAccount to a TeacherAccount.

Accounts are unique by username, so no two accounts can have the same name.

Both the StudentAccount and TeacherAccount have a foreign key to UserAccount

Thoughts?

promote a StudentAccount to a TeacherAccount

Being both? Not doable with an inheritance model.

Changing type? I would do that with an ad-hoc sql query. This is quite a special case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM