0

With FluentNHibernate I mapped a collection of interface by specifying the concrete type in the mapping class. I'm trying to convert to Maping.ByCode.

Entity classes:

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

With FluentNHibernate:

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

With Mapping 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()
  );

The mapping ByCode doesn't work. Is there a way to achieve what is done with Fluent NHibernate?

user995219
  • 104
  • 11

1 Answers1

1

Try setting Class:

Bag(x=>x.Children,
   m=> m.Key(k=>k.Column("Parent")),
   ce=> ce.OneToMany(m => m.Class(typeof(ChildEntity)))
  );
Roman Artiukhin
  • 2,200
  • 1
  • 9
  • 19