开发者

Index was out of range. Must be non-negative and less than the size of the collection error in Nhibernate

开发者 https://www.devze.com 2023-03-24 00:48 出处:网络
I receive the exception Index was out of range. Must be non-negative and less than the size of the collection

I receive the exception

Index was out of range. Must be non-negative and less than the size of the collection

when i try to SaveOrUpdate a Bsa object. I think the problem is that i map the same row twice, once as a property and once as a List of children.

    public BsaMap()
    {
        Schema("MYS");
        Table("BSA");
        Id(x => x.Id, "BSA_S").GeneratedBy.TriggerIdentity();
        HasMany(x => x.BitTypeList).KeyColumn("BSA_S").Fetch.Subselect().Inverse().Not.LazyLoad().Cascade.SaveUpdate();
    }

One Bsa has many BitTypes, and each BitType got the BSA_S as its foreign key. How should i map this, to avoid the error? I like having the I'd like to keep 开发者_高级运维the BSA_S as a property field.

Any advice?


Found the problem. In The BitType entity, i had mapped BSA_S twice, one as:

Map(x => x.BsaS).Column("BSA_S"); 

and:

References(x => x.Parent).Column("BSA_S").Cascade.None().Not.LazyLoad().Not.Nullable();
0

精彩评论

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