带有元素列表的映射字典

发布于 2024-12-08 14:59:34 字数 617 浏览 1 评论 0原文

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]]

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]]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

流年里的时光 2024-12-15 14:59:34

这里有一个需要跳过的圈

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

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<>
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文