开发者

Fluent NHibernate HasOne + HasMany with same child class

开发者 https://www.devze.com 2023-02-03 02:43 出处:网络
I have a class Employer which contains a collection of UserGroup but it also has another UserGroup called Administrators

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

精彩评论

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

关注公众号