Invalid index n for this SqlParameterCollection with Count=m

点点圈 提交于 2019-12-12 17:17:57

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/5096774/invalid-index-n-for-this-sqlparametercollection-with-count-m

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!