是否可以使用Fluent NHibernate映射具有以下签名的属性?
IDictionary<NavigationType, IList<NavigationActionEntity>> NavigationActions;
NavigationType
是枚举,NavigationActionEntity
是映射的实体
我试过这样的话:
HasManyToMany(x => x.NavigationActions).AsEntityMap()
.Table("CarrierNavigationActions");
但它给了我一个例外:
An association from the table CarrierNavigationActions refers to an unmapped
class: System.Collections.Generic.IList`1[[Dal.Entities.NavigationActionEntity]]
答案 0 :(得分:2)
这里有一个跳过的箍
class ActionsHolder
{
protected IList<TypeToEntity> innerList { get; set; }
public IDictionary<NavigationType, IList<NavigationActionEntity>> NavigationActions
{ get { return new NavigationTypeMap(innerList); } }
}
class TypeToEntity
{
public virtual NavigationType Type { get; set; }
public virtual NavigationActionEntity NavigationActionEntity { get; set; }
}
class MyClassMap : ClassMap<ActionsHolder>
{
public MyClassMap()
{
HasMany(Reveal.Member<ActionsHolder, IEnumerable<TypeToEntity>>("innerList"))
.Table("NavTypeToNavActionEntity")
.Component(c =>
{
c.Map(x => x.Type);
c.References(x => x.NavigationActionEntity).Not.LazyLoad();
})
;
}
}
class NavigationTypeMap : IDictionary<NavigationType, IList<NavigationActionEntity>>
{
private IList<TypeToEntity> innerList;
public NavigationTypeMap(IList<TypeToEntity> innerList)
{
// TODO: Complete member initialization
this.innerList = innerList;
}
// TODO: implementation of IDictionary<>
}