无法通过反射getter获得字段值... nhibernate使用二级缓存查询缓存 [英] could not get a field value by reflection getter... nhibernate query cache with 2nd level cache

查看:234
本文介绍了无法通过反射getter获得字段值... nhibernate使用二级缓存查询缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到这个异常

lockquote

无法获得字段值
反射getter
DictionaryMaster k__BackingField


这个内部异常:



类型中定义的字段'< k__BackingField'不是类型为
'System.Object []'的目标
对象上的字段。 p>

只有当我在查询中使用eagerloading时才存在这个问题。下面我把我的类,关系和查询。

  public class DictionaryMaster 
{
public virtual IList< DictionaryItem> DictionaryItems {get;私人设置}
public virtual System.String Code {get;私人设置}
public virtual System.String描述{get;私人设置}
}

public class DictionaryMasterMap:ClassMap< DictionaryMaster>
{
public DictionaryMasterMap()
{
Cache.ReadOnly()。Region(dictionary);
LazyLoad();

Id(x => x.Code)//我知道这是非常丑陋的
.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;私人设置}
公共虚拟字符串代码{get;私人设置}
public virtual DictionaryMaster DictionaryMaster {get;私人设置}
public virtual string描述{get;私人设置}
}

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);
引用(x => x.DictionaryMaster).Column(DI_DCCode);


code
$ b $ p $查询:

$ $ p $ session.Query< DictionaryMaster>()
.Fetch(x => x.DictionaryItems)
.Cacheable()
.CacheMode(CacheMode.Normal )
.ToList();


解决方案

我怀疑很多用户都面临这个问题 - 你取消选择答案作为选择的答案这个问题将得到更多的关注。 AFAIK仍然没有解决方法,允许在同一个调用中使用Linq,Cacheable()和Fetch()。

这是一个意见,但可能是因为我的低SO排名我还无法创建评论。



干杯,

Jonno


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

解决方案

I suspect many users are facing this problem - perhaps if you unmark your answer as the chosen answer the question will get more attention. AFAIK there's still no workaround which allows using Linq, Cacheable() and Fetch() at the same call.

This is meant as a comment, however probably because of my low SO ranking I can't create comments yet.

Cheers,

Jonno

这篇关于无法通过反射getter获得字段值... nhibernate使用二级缓存查询缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆