Search code examples
c#asp.netasp.net-mvcnhibernatenhibernate-mapping

Nhibernate exception: base {NHibernate.HibernateException} = {"illegal access to loading collection"}


I am working on an NHibernate exception :"base {NHibernate.HibernateException} = {"illegal access to loading collection"}"

Table PatRef is Parent table. Table PatCon is Sub table. When I retrieve data from PatRef to PatCons at debuging mode, the error message screen shot is below.

enter image description here

The Nhibernate data mapping screenshots are below.

Parent Table PatRef:

enter image description here

enter image description here

Sub Table PatCon: enter image description here

enter image description here

The implement for PatRefManagerProp.GetById enter image description here


Solution

  • The issue caused by:"a boolean field in your Project class may be marked as a varchar field in the database".

    I have a database column "ON_DIALYSIS" "VARCHAR2(1)", it was mapping as a bool in mapping class PatCon

    public virtual bool OnDialysis { get { return _onDialysis; } set { _onDialysis = value; } }

    After fix the mapping(change bool to string), everything became beautiful :-)

    public virtual string OnDialysis { get { return _onDialysis; } set { _onDialysis = value; } }