Hi, Andrea
A single object is different from a list. I have read some articles
before 2007 through search engine, they point out lazyload is just for
properties that in list type. Then I find that DataMapper-1.6.1 support
both concrete class and IList in 《Data Mapper Guide-1.6.1.chm》:
//////////3.5.4.9. lazyLoad
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.DynamicProxycomponent. In this case, you must declare all
methods/properties of the
class that you want to proxy as virtual.
/////////
But when I tried the feature (support concrete class), I failed even when I
did what the doc told to do (such as declare the properties as virtual
method and so on). As you see, I don't think my code or config is wrong, but
it just doesn't work. I also can't find an correct example. If you can,
could you please make a small example and mail me? It would be a big help
for me.
BTW: Please forgive my bad english. I am from China.
Andy
On 10/24/07, Andrea Tassinari <[EMAIL PROTECTED]> wrote:
>
> At 11.29 24/10/2007, Sandy Young wrote:
>
> >Hi, Andrea
> >
> >
> >Thanks you very much for your reply!
> >
> >But my work is different from yours. In my project, object subj to object
> reg is one-to-many relationship. So subj is a single object, not a IList.
>
> that should make no difference because a single object is a particular
> case of a list from the perspective of iBatis lazy load.
>
> I can't see anything wrong in your map except this little typo (note the
> space in the select attribute:
>
> <result property="Subj" column="SubjID" lazyLoad="true" select=" Subj.Find"
> />
>
> but if Subj.Find is a valid statement mapped to the same Type of the
> property Subj of class Reg, I can't see anything wrong. Remember that the
> object is lazy-loaded when a property of it is actually accessed, that is:
>
> Reg reg = ... //load from Database via ibatis, lets assume reg is not null
> now.
> Reg newReg = new Reg(); //instantiate a new reg object (just for the
> example)
>
> newReg.Subj = reg.Subj //this DOES NOT fire lazy load
> int dummy = reg.Subj.SubjId //this DOES fire lazy load, assuming SubjId is
> a property of class Subj
>
> Andrea
>
>
> >My configs are just like below:
> >
> >////In Reg.config:
> >
> ><resultMaps>
> > <resultMap id="SelectAllResult" class="Reg">
> > <result property="SeqId" column="SeqId"/>
> > <result property="UserID" column="UserID"/>
> > <result property="HoldScoreKind" column="HoldScoreKind"/>
> > <result property="IsTrain" column="IsTrain"/>
> > <result property="SubjID" column="SubjID"/>
> > <result property="FeeAffirm" column="FeeAffirm"/>
> > <result property="AffirmTime" column="AffirmTime"/>
> > </resultMap>
> > <resultMap id="SelectAllResultExtent" class="Reg"
> extends="SelectAllResult">
> > <result property="User" column="UserID" lazyLoad="true" select="
> User.Find" />
> > <result property="Subj" column="SubjID" lazyLoad="true" select="
> Subj.Find" />
> > </resultMap>
> > </resultMaps>
> >
> >/////In Subj.config:
> >
> ><select id="FindAll" resultMap="SelectAllResultExtent">
> > SELECT
> > *
> > FROM [Subj]
> > </select>
> ><select id="Find" parameterClass="int?"
> resultMap="SelectAllResultExtent" extends="FindAll">
> > WHERE
> > [Subj].[ID] = #value#
> > </select>
> >
> > Andy
> >
> >On 10/24/07, Andrea Tassinari <<mailto:[EMAIL PROTECTED]>
> [EMAIL PROTECTED] > wrote:
> >Hi,
> >
> >I am currently using DataMapper 1.6.1 and lazy load works great.
> >
> >One example:
> >
> >1) result Map for object Lotto containing a 1-to-many relationship mapped
> in my domain with a List<Cantina>
> >
> ><result property="Cantine" column="Id" select="SelectCantinaByLottoId"
> lazyLoad="true"/>
> >
> >Stupid question: did you specified a resultMap *not* a resultClass in the
> select statement?
> >
> ><!--Wrong version lazy load not involved -->
> ><select id="SelectLottoById" parameterClass="string" resultClass="Lotto">
> > <include refid="SelectLotto_BaseSQL" />
> > <dynamic prepend="WHERE">
> > <isParameterPresent>Id = #value#</isParameterPresent>
> > </dynamic>
> ></select>
> >
> ><!--Correct version lazy load fired -->
> ><select id="SelectLottoById" parameterClass="string"
> resultMap="LottoResMap">
> > <include refid="SelectLotto_BaseSQL" />
> > <dynamic prepend="WHERE">
> > <isParameterPresent>Id = #value#</isParameterPresent>
> > </dynamic>
> ></select>
> >
> >
> >Hope this helps
> >
> >Andrea
> >
> >At 10.38 24/10/2007, Sandy Young wrote:
> >
> >>When I use DataMapper-1.6.1 instead of DataMapper-1.5.1, I find the
> lazyload function doesn't work.
> >> If I replace DataMapper-1.6.1 with older DataMapper-1.5.1, it works.
> >> I find this bug is reported as a bug in <<http://ibatis.net>
> http://ibatis.net><http://ibatis.net>ibatis.net's Issue Tracker.
> >>Is there anybody can fix it?
> >>Thank you!
> >>
> >>My code:
> >>
> >>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, <<
> http://reg.Subj.Name>http://reg.Subj.Name><http://reg.Subj.Name>
> 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
> >> }
> >>
> >>
> >>No virus found in this incoming message.
> >>Checked by AVG Free Edition.
> >>Version: 7.5.503 / Virus Database: 269.15.8/1089 - Release Date:
> 23/10/2007 19.39
> >
> >
> >
> >
> >No virus found in this incoming message.
> >Checked by AVG Free Edition.
> >Version: 7.5.503 / Virus Database: 269.15.8/1089 - Release Date:
> 23/10/2007 19.39
>
>