我的Fluent nHibernate应用程序不是延迟加载

时间:2010-12-02 21:18:09

标签: c# database fluent-nhibernate lazy-loading

我有一个应用程序,在这个问题的末尾附加了映射类。

但是,当我使用此命令检索类的实例时:

        // this is NOT a SQL query. This queries the NHibernate object structure, so object names, properties and so forth
        // must track to the C# code, irrespective of the DB names
        IQuery query = Session.CreateQuery(string.Format( "from {0} c where c.Id = :id", table));
        query.SetString("id", id.ToString());
        IList list = query.List();
        if ( list.Count > 0 ) 
            return (WoWObject) query.List()[0];
        else            
            return null;       

应用程序挂起,因为每个引用都会从数据库中检索其引用。

我做错了什么?我一直坚持这个问题一个星期,谷歌似乎没有人遇到这样的问题。

类别:

    public sealed class creatureMap : ClassMap <creature>
    {
        public creatureMap()
        {

            Table("creature");
            LazyLoad();
            Id(x => x.Id, "Id");
            Map(x => x.Name, "name_lang0");
            Map(x => x.ArmorMulti, "acmulti");
            Map(x => x.age, "age");
            Map(x => x.alwaysitem0, "alwaysitem0");
            Map(x => x.alwaysitem1, "alwaysitem1");
            Map(x => x.alwaysitem2, "alwaysitem2");
            Map(x => x.attackbasetime, "attackbasetime");
            Map(x => x.attackcooldowntime, "attackcooldowntime");
            Map(x => x.attributemulti0, "attributemulti0");
            Map(x => x.attributemulti01, "attributemulti01");
            Map(x => x.attributemulti02, "attributemulti02");
            Map(x => x.attributemulti03, "attributemulti03");
            Map(x => x.attributemulti04, "attributemulti04");
            Map(x => x.auctionhouseid, "auctionhouseid");
            Map(x => x.bankerid, "bankerid");
            Map(x => x.basicammo, "basicammo");
            Map(x => x.battlegroundmapid, "battlegroundmapid");
            Map(x => x.battlemasterlistid, "battlemasterlistid");
            Map(x => x.binderid, "binderid");
            Map(x => x.caste, "caste");
            Map(x => x.ClassId, "class");
            Map(x => x.classification, "classification");
            Map(x => x.creaturefamily, "creaturefamily");
            References(x => x.creaturemovementinfoid, "creaturemovementinfoid").NotFound.Ignore().LazyLoad();
            References(x => x.CreatureType, "creaturetype").NotFound.Ignore().LazyLoad();
            Map(x => x.cursorname, "cursorname");
            Map(x => x.damageclass, "damageclass");
            Map(x => x.damageimmunity, "damageimmunity");
            Map(x => x.DMGMulti, "damagemulti");
            References(x => x.defaultlootid, "defaultlootid").NotFound.Ignore().LazyLoad();
            References(x => x.defaultlootid1, "defaultlootid1").NotFound.Ignore().LazyLoad();
            References(x => x.difficultycreatureid0, "difficultycreatureid0").NotFound.Ignore().LazyLoad();
            References(x => x.difficultycreatureid1, "difficultycreatureid1").NotFound.Ignore().LazyLoad();
            References(x => x.difficultycreatureid2, "difficultycreatureid2").NotFound.Ignore().LazyLoad();
            References(x => x.difficultycreatureid3, "difficultycreatureid3").NotFound.Ignore().LazyLoad();
            References(x => x.displayid, "displayid").NotFound.Ignore().LazyLoad();
            References(x => x.displayid1, "displayid1").NotFound.Ignore().LazyLoad();
            References(x => x.displayid2, "displayid2").NotFound.Ignore().LazyLoad();
            References(x => x.displayid3, "displayid3").NotFound.Ignore().LazyLoad();
            Map(x => x.displayprobability, "displayprobability");
            Map(x => x.displayprobability1, "displayprobability1");
            Map(x => x.displayprobability2, "displayprobability2");
            Map(x => x.displayprobability3, "displayprobability3");
            Map(x => x.dmgvariance, "dmgvariance");
            References(x => x.Combat, "dungeonencounterid").NotFound.Ignore().LazyLoad();
            Map(x => x.PowerMulti, "energymulti");
            Map(x => x.expansionid, "expansionid");
            References(x => x.factionid, "factionid").NotFound.Ignore().LazyLoad();
            Map(x => x.fatalfalldist, "fatalfalldist");
            Map(x => x.flags, "flags");
            Map(x => x.flagsex, "flagsex");
            Map(x => x.flagsexb, "flagsexb");
            Map(x => x.flagsexc, "flagsexc");
            Map(x => x.flagsexd, "flagsexd");
            Map(x => x.gender, "gender");
            References(x => x.gossipid, "gossipid").NotFound.Ignore().LazyLoad();
            Map(x => x.healthmodifier, "healthmodifier");
            Map(x => x.HPMulti, "hpmulti");
            References(x => x.immunitiesid, "immunitiesid").NotFound.Ignore().LazyLoad();
            References(x => x.interactconditionid, "interactconditionid").NotFound.Ignore().LazyLoad();
            References(x => x.interactspellid, "interactspellid").NotFound.Ignore().LazyLoad();
            Map(x => x.internalname_flag, "internalname_flag");
            Map(x => x.InternalName, "internalname_lang0");
            Map(x => x.killfactionadjustcap, "killfactionadjustcap");
            References(x => x.killfactionadjustid, "killfactionadjustid").NotFound.Ignore().LazyLoad();
            Map(x => x.killfactionadjustmulti, "killfactionadjustmulti");
            Map(x => x.maxdamage, "maxdamage");
            Map(x => x.MaxLevel, "maxlevel");
            Map(x => x.maxrangeddamage, "maxrangeddamage");
            References(x => x.meleeonlystringidnum0, "meleeonlystringidnum0").NotFound.Ignore().LazyLoad();
            References(x => x.meleeonlystringidnum1, "meleeonlystringidnum1").NotFound.Ignore().LazyLoad();
            Map(x => x.memo, "memo");
            Map(x => x.mindamage, "mindamage");
            Map(x => x.minimapblip, "minimapblip");
            References(x => x.minimapblipconditionid, "minimapblipconditionid").NotFound.Ignore().LazyLoad();
            Map(x => x.MinLevel, "minlevel");
            Map(x => x.minrangeddamage, "minrangeddamage");
            References(x => x.mountcreatureid, "mountcreatureid").NotFound.Ignore().LazyLoad();
            Map(x => x.name_flag, "name_flag");
            Map(x => x.name1_flag, "name1_flag");
            Map(x => x.name1_lang0, "name1_lang0");
            Map(x => x.name2_flag, "name2_flag");
            Map(x => x.name2_lang0, "name2_lang0");
            Map(x => x.name3_flag, "name3_flag");
            Map(x => x.name3_lang0, "name3_lang0");
            Map(x => x.npcinteractions, "npcinteractions");
            Map(x => x.npcsoundid, "npcsoundid");
            Map(x => x.numhelpfulauras, "numhelpfulauras");
            References(x => x.onkillquestclear0, "onkillquestclear0").NotFound.Ignore().LazyLoad();
            References(x => x.onkillquestclear1, "onkillquestclear1").NotFound.Ignore().LazyLoad();
            References(x => x.onkillquestcomplete0, "onkillquestcomplete0").NotFound.Ignore().LazyLoad();
            References(x => x.onkillquestcomplete1, "onkillquestcomplete1").NotFound.Ignore().LazyLoad();
            Map(x => x.patch_id, "patch_id");
            Map(x => x.petitionid, "petitionid");
            Map(x => x.petitionitemlistid, "petitionitemlistid");
            Map(x => x.petpersonality, "petpersonality");
            Map(x => x.petspellsid, "petspellsid");
            References(x => x.phasegroupid, "phasegroupid").NotFound.Ignore().LazyLoad();
            References(x => x.phaseid, "phaseid").NotFound.Ignore().LazyLoad();
            References(x => x.phaseshift, "phaseshift").NotFound.Ignore().LazyLoad();
            Map(x => x.phaseuseflags, "phaseuseflags");
            References(x => x.pickpocketlootid, "pickpocketlootid").NotFound.Ignore().LazyLoad();
            Map(x => x.playerclass, "playerclass");
            Map(x => x.preferredammo, "preferredammo");
            References(x => x.proxycreatureid, "proxycreatureid").NotFound.Ignore().LazyLoad();
            References(x => x.proxycreatureid1, "proxycreatureid1").NotFound.Ignore().LazyLoad();
            Map(x => x.pvppoints, "pvppoints");
            References(x => x.questgiverid, "questgiverid").NotFound.Ignore().LazyLoad();
            References(x => x.radiid, "radiid").NotFound.Ignore().LazyLoad();
            References(x => x.randomtext0, "randomtext0").NotFound.Ignore().LazyLoad();
            References(x => x.randomtext1, "randomtext1").NotFound.Ignore().LazyLoad();
            Map(x => x.randomtext2, "randomtext2");
            Map(x => x.ranking, "ranking");
            Map(x => x.recordlocked, "recordlocked");
            Map(x => x.referenceflag, "referenceflag");
            Map(x => x.required_expansion, "required_expansion");
            Map(x => x.resistbonus0, "resistbonus0");
            Map(x => x.resistbonus1, "resistbonus1");
            Map(x => x.resistbonus2, "resistbonus2");
            Map(x => x.resistbonus3, "resistbonus3");
            Map(x => x.resistbonus4, "resistbonus4");
            Map(x => x.resistbonus5, "resistbonus5");
            Map(x => x.resistbonus6, "resistbonus6");
            Map(x => x.resistscale0, "resistscale0");
            Map(x => x.resistscale1, "resistscale1");
            Map(x => x.resistscale2, "resistscale2");
            Map(x => x.resistscale3, "resistscale3");
            Map(x => x.resistscale4, "resistscale4");
            Map(x => x.resistscale5, "resistscale5");
            Map(x => x.resistscale6, "resistscale6");
            Map(x => x.ridevehiclecreatureid, "ridevehiclecreatureid");
            Map(x => x.runspeed, "runspeed");
            Map(x => x.schoolimmunity, "schoolimmunity");
            References(x => x.skinninglootid, "skinninglootid").NotFound.Ignore().LazyLoad();
            References(x => x.spawnspellid, "spawnspellid").NotFound.Ignore().LazyLoad();
            Map(x => x.spellimmunity0, "spellimmunity0");
            Map(x => x.spellimmunity01, "spellimmunity01");
            References(x => x.spellsid, "spellsid").NotFound.Ignore().LazyLoad();
            Map(x => x.startanimstate, "startanimstate");
            Map(x => x.stateimmunity0, "stateimmunity0");
            Map(x => x.stateimmunity01, "stateimmunity01");
            Map(x => x.stringid0, "stringid0");
            Map(x => x.stringid1, "stringid1");
            References(x => x.stringidnum0, "stringidnum0").NotFound.Ignore().LazyLoad();
            References(x => x.stringidnum1, "stringidnum1").NotFound.Ignore().LazyLoad();
            Map(x => x.targetframepriority, "targetframepriority");
            Map(x => x.taxinodeid, "taxinodeid");
            Map(x => x.template, "template");
            Map(x => x.title_flag, "title_flag");
            Map(x => x.title_lang0, "title_lang0");
            References(x => x.trainerid, "trainerid").NotFound.Ignore().LazyLoad();
            References(x => x.triggersid, "triggersid").NotFound.Ignore().LazyLoad();
            References(x => x.VehicleRec, "vehicleid").NotFound.Ignore().LazyLoad();
            References(x => x.vendoritemlist, "vendoritemlist").NotFound.Ignore().LazyLoad();
            References(x => x.vendorlist0, "vendorlist0").NotFound.Ignore().LazyLoad();
            References(x => x.vendorlist01, "vendorlist01").NotFound.Ignore().LazyLoad();
            References(x => x.vendorlist02, "vendorlist02").NotFound.Ignore().LazyLoad();
            References(x => x.vendorlist03, "vendorlist03").NotFound.Ignore().LazyLoad();
            References(x => x.vendorlist04, "vendorlist04").NotFound.Ignore().LazyLoad();
            References(x => x.vendorlist05, "vendorlist05").NotFound.Ignore().LazyLoad();
            Map(x => x.walkspeed, "walkspeed");
            Map(x => x.woweditlock, "woweditlock");
            Map(x => x.woweditlockuser, "woweditlockuser");
            Map(x => x.XpMulti, "xpmulti");
        }
    }
}

2 个答案:

答案 0 :(得分:2)

你真的,真的需要重构你的课程,因此你的地图。它太大了。单一责任原则 - 一个班级应该只有一个改变的理由。你的太多了。

祝你好运..

答案 1 :(得分:0)

显然,NotFound.Ignore()会导致NHibernate急切地获取引用的实体。您是否可以重新构建代码以消除NotFound.Ignore()

的需要

以下是一些链接,可以阐明这一点:

希望这有帮助,

相关问题