以前使用DataMapper-1.6.1,现在改用DataMapper-1.5.1,结果lazyload无效了。
以下引用《Data Mapper Guide-1.6.1.chm》中的内容:

3.5.4.9. lazyLoad

Use the lazyLoad attribute with the select attribute to indicate whether or
not the select statement's results should be lazy loaded. This can provide a
performance boost by delaying the loading of the select statement's results
until they are needed/accessed.

Lazy loading is supported transparently for IList and IList<T>
implementation.

Lazy loading is supported on strongly typed collection via
Castle.DynamicProxy component. In this case you must set the listClass attribute
and declare all methods/properties of the typed collection that you want to
proxy as virtual.

Lazy loading is supported on concrete class via Castle.DynamicProxy
component. In this case, you must declare all methods/properties of the class
that you want to proxy as virtual.


在1.5.1版本中,我没有把lazyload属性定义为virtual都可以使用lazyload功能,现在即使声明为virtual也没有效果。调试的过程中发现,属性的第一次读取是肯定为空的,而之后lazyload属性的值却有可能获取。深入分析代码并把1.6.1和1.5.1做比较,无奈水平有限,发现直接相关的代码似乎没有改动,没看出端倪。

在Ibatis.Net的Issue Tracker上看到了此bug的报告,但是没有评论和解决方案。不知道cnblogs上研究Ibatis.Net的牛人能不能提供帮助?实在不行,只有使用1.5.1了。

附代码:

IRegDao dao
=

new
RegDao();
Reg reg

=
dao.Find(
1
);
Console.WriteLine(

"
Reg:
"
);
Console.WriteLine(

"
SeqId:{0}
"
, reg.SeqId);
Console.WriteLine(

"
SubjID:{0}\tName:{1}
"
, reg.SubjID, reg.Subj.Name);


///
class Reg


public
partial
class
Reg
{

#region
Private Member


private

int
?
_SubjID;

#endregion



#region
Private Extend Member


private
Subj _Subj;

#endregion



#region
Constructor


public
Reg()
{
}

#endregion



#region
Public Properties


public

int
?
SubjID
{

get
{
return
_SubjID;}

set
{_SubjID
=
value;}
}

#endregion



#region
Public Extend Properties


public

virtual
Subj Subj
{

get
{
return
_Subj; }

set
{ _Subj
=
value; }
}

#endregion

}


标签: none

添加新评论