I got this exception
could not get a field value by reflection getter of DictionaryMaster.
k__BackingField
with this inner exception:
Field '<>k__BackingField' defined on type is not a field on the target object which is of type 'System.Object[]'.
The problem exists only when i use eagerloading in query. Below i put my classes, relations and query.
public class DictionaryMaster
{
public virtual IList<DictionaryItem> DictionaryItems { get; private set; }
public virtual System.String Code { get; private set; }
public virtual System.String Description { get; private set; }
}
public class DictionaryMasterMap : ClassMap<DictionaryMaster>
{
public DictionaryMasterMap()
{
Cache.ReadOnly().Region("dictionary");
LazyLoad();
Id(x => x.Code) //i know this is so ugly
.Column("DC_Code")
.GeneratedBy.Assigned();
Map(x => x.Description).Column("DC_Desc");
HasMany(x => x.DictionaryItems)
.Cascade.AllDeleteOrphan()
.Fetch.Select()
.AsBag()
.Inverse()
.Not.LazyLoad()
.KeyColumns.Add("DI_DCCode");
}
}
public class DictionaryItem
{
public virtual int Id { get; private set; }
public virtual string Code { get; private set; }
public virtual DictionaryMaster DictionaryMaster { get; private set; }
public virtual string Description { get; private set; }
}
public class DictionaryItemMap : ClassMap<DictionaryItem>
{
public DictionaryItemMap()
{
Cache.ReadOnly().Region("dictionary");
Id(x => x.Id)
.Column("DI_Id").GeneratedBy.Identity();
Map(x => x.Code).Column("DI_Code");
Map(x => x.Description).Column("DI_Desc");
References(x => x.DictionaryMaster).Column("DI_DCCode");
}
}
Query:
session.Query<DictionaryMaster>() .Fetch(x => x.DictionaryItems) .Cacheable() .CacheMode(CacheMode.Normal) .ToList();