开发者

Map Dictionary with list of elements

Is it possible with Fluent NHibernate to map a property with开发者_如何学运维 the following signature?

IDictionary<NavigationType, IList<NavigationActionEntity>> NavigationActions;

NavigationType is an enum, NavigationActionEntity is a mapped entity.

I tried it like this:

HasManyToMany(x => x.NavigationActions).AsEntityMap()
                                       .Table("CarrierNavigationActions");

But it is giving me an exception:

An association from the table CarrierNavigationActions refers to an unmapped
class: System.Collections.Generic.IList`1[[Dal.Entities.NavigationActionEntity]]


here a hoop to jump through

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜