【问题标题】:Mapping a collection of Interface with NHibernate Mapping ByCode使用 NHibernate Mapping ByCode 映射接口集合
【发布时间】:2019-08-06 20:12:21
【问题描述】:

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

实体类:

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");
}
}

使用映射 ByCode:

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 的功能?

【问题讨论】:

    标签: nhibernate nhibernate-mapping-by-code


    【解决方案1】:

    尝试设置Class:

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

    【讨论】:

    • 就是这样。谢谢。
    猜你喜欢
    • 2014-06-26
    • 1970-01-01
    • 1970-01-01
    • 2010-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多