NHibernate 从一对多到一对一
我正在为正在创建的软件创建安全系统,我想知道如何在 NHibernate 中执行以下操作(如果可能的话)
用户帐户类别:
public class UserAccount
{
public virtual int UserID { get; set; }
public virtual String Username { get; set; }
public virtual Privilege InvoicePrivilege { get; set; }
public virtual Privilege TradePrivilege { get; set; }
}
权限类别:
public class Privilege
{
public virtual bool Read { get; set; }
public virtual bool Write { get; set; }
public virtual bool Delete { get; set; }
public virtual bool Modify { get; set; }
}
我将拥有大量这些权限对象(每个交易实体一个),因此在数据库中我有以下表格:
UserAccounts(UserID,用户名)
权限(UserID、PrivilegeType、读取、写入、修改、删除)
如何将 InvoicePrivielge 属性从用户帐户映射到 (UserID, 'Invoice') 权限。
我可以使用多对一来完成此操作,但我不需要一组权限,我宁愿将其映射到其属性。
I am creating the security system for the software im creating and I would like to know how i can do the following in NHibernate(if at all possible)
User Account Class:
public class UserAccount
{
public virtual int UserID { get; set; }
public virtual String Username { get; set; }
public virtual Privilege InvoicePrivilege { get; set; }
public virtual Privilege TradePrivilege { get; set; }
}
Privilege Class:
public class Privilege
{
public virtual bool Read { get; set; }
public virtual bool Write { get; set; }
public virtual bool Delete { get; set; }
public virtual bool Modify { get; set; }
}
I will be having a large number of these privilege objects (one for each traded entity) so in the database i have the following tables:
UserAccounts ( UserID, Username)
Privileges (UserID, PrivilegeType, Read,Write,Modify,Delete)
How can I map the InvoicePrivielge property from the user account to the (UserID, 'Invoice') Privilege.
I could do this using many-to-one but I don't want a collection of privileges, i'd rather map it to its property.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为实现此目的的一种方法是创建 Privilege 类的两个子类:
并设置鉴别器列和值。在流畅的映射中:
并使用
UserAccount
中的子类I think a way to do this is to create two subclasses of the Privilege class:
and set the discriminator column and value. In fluent mapping:
and use the subclasses in the
UserAccount