IBATISNET中的lazyLoad

使用IBATISNET免不了用到lazyload特性,这样可以实现延迟加载,提高数据库访问效率。但使用lazyload的时候要小心,别忘了给需要lazyload的属性加上virtual关键字哦,不然的话无法实现延迟加载的(我发现在单步调试的时候反而可以延迟加载)。

映射文件:

    <resultMap id="ApplicationResult" class="Application">
      
<result property="Id" column="id" dbType="guid"/>
      
<result property="YearNum" column="yearnum"/>

      
<result property="Budget.XMLValue" column="budget"/>
      
<result property="StudentInfo" column='id' select="Application.SelectStudentInfo" lazyLoad="true"/>
      
<result property="TeacherInfo" column="id" select="Application.SelectTeacherInfo" lazyLoad="true"/>

    
</resultMap>

 

对应的Model

 

    [Serializable]
    
public class Application
    {
        
#region Model
        
private Guid _id = Guid.Empty;

        
private IList<StudentInfo> _students = new List<StudentInfo>(0);
        
private IList<TeacherInfo> _teachers = new List<TeacherInfo>(0);

        
public Application()
        { }

        
public Guid Id
        {
            
set { _id = value; }
            
get { return _id; }
        }

        
public virtual IList<StudentInfo> StudentInfo
        {
            
get { return _students; }
            
set { _students = value; }
        }

        
public virtual IList<TeacherInfo> TeacherInfo
        {
            
get { return _teachers; }
            
set { _teachers = value; }
        }

}
posted @ 2011-11-14 10:14  awp110  阅读(358)  评论(0编辑  收藏  举报