获取“无法将 PersistentGenericSet 转换为 ISet”错误

发布于 2024-11-14 02:01:30 字数 1169 浏览 2 评论 0 原文

我收到此错误:

无法转换类型的对象 'NHibernate.Collection.Generic.PersistentGenericSet1[IocWinFormTestEntities.People]' 输入“System.Collections.Generic.ISet1[IocWinFormTestEntities.People]”。

实体:

public class Event 
{
    public Event()
    {
        this.People = new HashSet<People>();
    }
    public virtual Guid Id { get; private set; }

    public virtual ISet<People> People { get; set; }
}

映射覆盖类:

public class EventMapOverride : IAutoMappingOverride<Event>
{
    public void Override(AutoMapping<Event> mapping)
    {
        mapping.HasMany(c => c.People)
            .AsSet()
            .Cascade.AllDeleteOrphan();
    }
}

从流畅的自动映射器生成 hbm:

<set cascade="all-delete-orphan" name="People">
    <key>
        <column name="Event_id" />
    </key>
    <one-to-many class="IocWinFormTestEntities.People, IocWinFormTestEntities, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</set>

出了什么问题?

I get this error:

Unable to cast object of type
'NHibernate.Collection.Generic.PersistentGenericSet1[IocWinFormTestEntities.People]'
to type 'System.Collections.Generic.ISet
1[IocWinFormTestEntities.People]'.

The entity:

public class Event 
{
    public Event()
    {
        this.People = new HashSet<People>();
    }
    public virtual Guid Id { get; private set; }

    public virtual ISet<People> People { get; set; }
}

Map override class:

public class EventMapOverride : IAutoMappingOverride<Event>
{
    public void Override(AutoMapping<Event> mapping)
    {
        mapping.HasMany(c => c.People)
            .AsSet()
            .Cascade.AllDeleteOrphan();
    }
}

Generated hbm from fluent automapper:

<set cascade="all-delete-orphan" name="People">
    <key>
        <column name="Event_id" />
    </key>
    <one-to-many class="IocWinFormTestEntities.People, IocWinFormTestEntities, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</set>

What's wrong?

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

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

发布评论

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

评论(3

一百个冬季 2024-11-21 02:01:30

您的问题是您在 System.Collections 中使用 ISet .Generic 命名空间,但 nHibernate 希望 ISet 为 Iesi.Collections.Generic.ISet。因此,将属性定义更改为“

public virtual Iesi.Collections.Generic.ISet<People> People { get; set; }

如果您想使用 .net 4 ISet<>” 接口,请执行此 文章

Your problem is you are using ISet in System.Collections.Generic namespace but nHibernate expects ISet to be Iesi.Collections.Generic.ISet<>. So change your property definition to

public virtual Iesi.Collections.Generic.ISet<People> People { get; set; }

If you want to use .net 4 ISet<> interface, go through this article

℡寂寞咖啡 2024-11-21 02:01:30

最新的NHibernate使用Iesi.Collections.ISet,而不是System.Collections.Generic.ISet。您可以引用 Iesi 程序集或使用 System.Collections.Generic.ICollection:

public virtual ICollection<People> People { get; set; }

ISet 接口继承自 ICollection。

The latest NHibernate uses Iesi.Collections.ISet, not System.Collections.Generic.ISet. You can either reference the Iesi assembly or use System.Collections.Generic.ICollection:

public virtual ICollection<People> People { get; set; }

The ISet interface inherits from ICollection.

殊姿 2024-11-21 02:01:30

在 Nhibernate 4 中,使用 System.Collections.Generic.ISet<> 现在是 要走的路

此问题中显示的错误不应再发生。

With Nhibernate 4, using System.Collections.Generic.ISet<> is now the way to go.

The error showcased in this question should no longer occur.

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