2011-10-06 86 views
1

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<> 
} 
+0

謝謝。我想我會介入一個簡單的實體。這看起來像是矯枉過正...... –