2011-02-14 65 views
2

在我的应用我有3个实体:功能NHibernate - 许多一对多和复合键

class User 
{ 
    public List<Role> Roles { get; protected set; } 
} 

class Role 
{ 
    public List<User> Users { get; protected set; } 
} 

internal class UserInRole 
{ 
    public User User { get; protected set; } 
    public Role Role { get; protected set; } 
    public string Flag { get; protected set; } 
} 

(是的,我知道这是可能产生不UserInRole实体许多一对多的关系,但我需要它)

而在结果我想有3个表。表UserInRole必须具有UserId和RoleId的组合键。现在我的UserInRole映射看起来像这里:

CompositeId() 
    .KeyReference(x => x.User) 
    .KeyReference(x => x.Role); 

但它不起作用。

任何帮助?

+0

你是什么意思,它不起作用?你是否得到某种可以分享的错误/异常? – gillyb 2013-02-09 20:17:56

回答

-3

这听起来像你试图实现与NHibernate的asp.net成员资格和角色提供者...

我说得对不对?

如果是这样,不要浪费时间重新发明车轮。 Check this out

+1

Thx为链接,非常有用。但角色,用户和UserInRole就是例子。我有像这样的结构的真正的商业实体。 – griZZZly8 2011-02-15 05:12:44