开发者

Fluent NHibernate HasOne + HasMany with same child class

I have a class Employer which contains a collection of UserGroup but it also has another UserGroup called Administrators

the idea is that an employer always has one administrators group with all permissions etc. But they can create arbitrary groups as they see fit.

  public class Employer
  {
     public virtual UserGroup Administrators { get; set; }
     public virtual IList<UserGroup> UserGroups { get; set; }
  }

The Mappings are:

mapping.HasOne(x => x.Administrators)
       .PropertyRef(g => g.Employer)
       .Constrained() //Lazy load
       .Cascade.All();


mapping.HasMany开发者_如何学编程(x => x.UserGroups).Inverse();

The problem is, when a query for an Employer is made, it always returns more than one row for groups, e.g. Admins + Managers etc...

Is it possible to use the same Type in for two purposes on one class like above?? What other alternatives do I have to express this?

Cheers...


You can map the same class in multiple ways by using entity names. Will try to post example later.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜