简体   繁体   English

NHibernate移动实体到不同的表

[英]NHibernate moving entity to different table

Using NHibernate I've got an account system set-up, with different kinds of accounts (different privileges, etc.) 使用NHibernate,我有一个帐户系统设置,具有不同类型的帐户(不同的特权等)。

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. 在提供的示例中,我希望能够将StudentAccount提升为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 StudentAccount和TeacherAccount都具有UserAccount的外键

Thoughts? 有什么想法吗?

promote a StudentAccount to a TeacherAccount 将StudentAccount提升为TeacherAccount

Being both? 都是吗? Not doable with an inheritance model. 不适用于继承模型。

Changing type? 改变类型? I would do that with an ad-hoc sql query. 我会用临时SQL查询来做到这一点。 This is quite a special case. 这是很特殊的情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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