此 SqlParameterCollection 的索引 n 无效,且 Count=m

发布于 2024-10-19 01:54:47 字数 830 浏览 0 评论 0原文

当我尝试保存一个类时,我在 Castle Active Record(包裹在 NHibernate 周围)中遇到了这个讨厌的错误:

Invalid index n for this SqlParameterCollection with Count=m

我知道这个错误是由属性在一个类中被映射多次,但我不知道如何解决它。我有两个子类,它们都使用同一列 (IpAddressNumber) 映射回相关类。另外,IpAddressNumber 是该类的主键,这会导致 NHibernate 尝试映射 IpAddressNumber 属性三次(只是猜测)。

这是该类:

[ActiveRecord(Lazy=true)]
    public class DeviceConfiguration : UsersDatabase<DeviceConfiguration>
    {
        [PrimaryKey]
        public virtual long IPAddressNumber { get; set; }

        [BelongsTo("IPAddressNumber", Lazy = FetchWhen.OnInvoke)]
        public virtual Vehicle Vehicle { get; set; }

        [BelongsTo("IPAddressNumber", Lazy = FetchWhen.OnInvoke)]
        public virtual JBusConfiguration JBusConfiguration { get; set; }
}

任何帮助将不胜感激...

I'm getting this nasty error in Castle Active Record (wrapped around NHibernate) when I try to save a class:

Invalid index n for this SqlParameterCollection with Count=m

I know that this error is caused by a property being mapped multiple times in a class however I'm not sure how to get around it. I have two child classes that both map back to the class in question using the same column (IpAddressNumber). Also IpAddressNumber is the primary key of the class, which results in NHibernate trying to map the IpAddressNumber property three times (just a guess.)

Here is the class:

[ActiveRecord(Lazy=true)]
    public class DeviceConfiguration : UsersDatabase<DeviceConfiguration>
    {
        [PrimaryKey]
        public virtual long IPAddressNumber { get; set; }

        [BelongsTo("IPAddressNumber", Lazy = FetchWhen.OnInvoke)]
        public virtual Vehicle Vehicle { get; set; }

        [BelongsTo("IPAddressNumber", Lazy = FetchWhen.OnInvoke)]
        public virtual JBusConfiguration JBusConfiguration { get; set; }
}

Any help would be greatly appreciated...

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

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

发布评论

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

评论(1

仅一夜美梦 2024-10-26 01:54:47

我最终不得不完全删除第二个关联来解决这个问题。这不是一个很好的解决方案,但却是我能找到的唯一一个。

I ended up having to just remove the second association altogether to get around this issue. Not a great solution but the only one I could find.

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