使用 NHibernate 映射 ByCode 映射接口集合

Mapping a collection of Interface with NHibernate Mapping ByCode

使用 FluentNHibernate,我通过在映射 class 中指定具体类型来映射接口集合。我正在尝试转换为 Maping.ByCode.

实体class是:

public class Parent Entity
{
public virtual Guid Id{get;set;}
public virtual IList<IChildEntity> Children{get;set;}
}

public class ChilEntity:IChildEntity
{
public virtual Guid Id{get;set;}
}

使用 FluentNHibernate:

public class ParentEntityMap:ClassMap<ParentEntity>
{
public ParentEntityMap()
{
Table("ParentEntity");
Id(x => x.Id);
HasMany<ChildEntity>(x=>x.Children)
 .KeyColumn("Parent");
}
}

使用映射代码:

public class ParentEntityMap:ClassMapping<ParentEntity>
{
 Public ParentEntityMap()
 {
  Table("ParentEntity");
  Id(x=>x.Id);
  Bag<ChildEntity>(x=>(IList<ChildEntity>)x.Children,
   m=>m.Key(k=>k.Column("Parent")),
   ce=>ce.OneToMany()
  );

映射 ByCode 不起作用。有没有办法实现 Fluent NHibernate 的功能?

尝试设置 Class:

Bag(x=>x.Children,
   m=> m.Key(k=>k.Column("Parent")),
   ce=> ce.OneToMany(m => m.Class(typeof(ChildEntity)))
  );