Is Lazy Loading required for nHibernate?

后端 未结 2 776
感情败类
感情败类 2021-02-03 14:44

It took me a long time but I finally got nHibernate\'s Hello World to work. It worked after I did \"lazy loading.\" Honestly, I couldn\'t tell you why it all worked, but it di

2条回答
  •  失恋的感觉
    2021-02-03 15:15

    If you're using hbm.xml files for you mapping simply adding a lazy="false" to the element will get you non-lazy loading for all simple properties. Foreign entities will still be lazy by default. To make them eager add lazy="false" to the mapping element. One benefit of eager loading is you will no longer need virtual properties on your entity classes.

    Edit: If you really want to find out what's going on behind the scenes, NHibernate logs everything using log4net. Adding

    
      

    inside in your web.config will spit all the SQL NHibernate generates the file c:\logs\sql.log

提交回复
热议问题