简体   繁体   中英

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

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM