How to implement lazy load in 3.7.0.0

How to implement lazy load in 3.7.0.0

Old forum URL: forums.lhotka.net/forums/t/7623.aspx


zhengokusa posted on Monday, September 14, 2009

Hello

I have a huge one to many Read only BO like the code below.

 protected void DataPortal_Fetch(SingleCriteria<ROManfacRoot, int> criteria)
        {
            using (SqlConnection connection = new SqlConnection(DataConnection.ConnectionString))
            {
                connection.Open();
                using (SqlCommand command = new SqlCommand("sp_ROManfacRoot_Get", connection))
                {
                    command.CommandType = System.Data.CommandType.StoredProcedure;
                    command.Parameters.Add(new SqlParameter("@pk_ID", criteria.Value));
                    using (Csla.Data.SafeDataReader reader = new Csla.Data.SafeDataReader(command.ExecuteReader()))
                    {
                        if (reader.Read())
                        {
                            LoadProperty<int>(ManfacIdProperty, reader.GetInt32("MANFAC_ID"));
                            LoadProperty<int>(LicensorIdProperty, reader.GetInt32("LICENSOR_ID"));
                            LoadProperty<int>(LeadIdProperty, reader.GetInt32("LEAD_ID"));
                            LoadProperty<string>(ParentFlagProperty, reader.GetString("PARENT_FLAG"));
                            LoadProperty<int>(ManfacStageIdProperty, reader.GetInt32("MANFAC_STAGE_ID"));
                            LoadProperty<string>(ManfacNameProperty, reader.GetString("MANFAC_NAME"));
                            LoadProperty<string>(StatusProperty, reader.GetString("STATUS"));
                            LoadProperty<string>(Addr1Property, reader.GetString("ADDRESS1"));
                            LoadProperty<string>(Addr2Property, reader.GetString("ADDRESS2"));
                            LoadProperty<string>(CityProperty, reader.GetString("CITY"));
                            LoadProperty<string>(StateProperty, reader.GetString("STATE"));
                            LoadProperty<string>(ZipProperty, reader.GetString("ZIP"));
                            LoadProperty<string>(ProvinceProperty, reader.GetString("PROVINCE"));
                            LoadProperty<string>(CountryProperty, reader.GetString("COUNTRY"));
                            LoadProperty<string>(Phone1Property, reader.GetString("PHONE1"));
                            LoadProperty<string>(Phone2Property, reader.GetString("PHONE2"));
                            LoadProperty<string>(PhoneMobProperty, reader.GetString("MOBILE"));
                            LoadProperty<string>(PhoneFaxProperty, reader.GetString("FAX"));
                            LoadProperty<string>(EmailProperty, reader.GetString("EMAIL"));
                            LoadProperty<string>(WebsiteProperty, reader.GetString("WEBSITE"));
                            LoadProperty<string>(Comment1Property, reader.GetString("COMMENT1"));
                            LoadProperty<string>(Comment2Property, reader.GetString("COMMENT2"));
                        }
                        reader.NextResult();
                        LoadProperty<ROManfacContactColl>(ManfacContactsProperty, ROManfacContactColl.GetList(reader));
                        reader.NextResult();
                        LoadProperty<ROAgreeColl>(ManfacAgreeProperty, ROAgreeColl.GetList(reader));
                        reader.NextResult();
                        LoadProperty<ROManfacPartnerColl>(ManfacPartnersProperty, ROManfacPartnerColl.GetList(reader));
                        reader.NextResult();
                       }
                }
                connection.Close();
            }

My question is how can I implement a lazy load on those collection objects.

LoadProperty<ROManfacContactColl>(ManfacContactsProperty, ROManfacContactColl.GetList(reader));

LoadProperty<ROAgreeColl>(ManfacAgreeProperty, ROAgreeColl.GetList(reader));

LoadProperty<ROManfacPartnerColl>(ManfacPartnersProperty, ROManfacPartnerColl.GetList(reader));

Thanks alot

 

 

JonnyBee replied on Monday, September 14, 2009

Hi Zane,

In short - code these RO lists as "root" objects in the sense that they are standalone liste with static Get methods and implement their own DataPortal_Fetch (or ObjectFactory).

These classes may also need to implement own criteria classes.

/jonnybee

zhengokusa replied on Monday, September 14, 2009

Thank you for your response.

As my understanding, in the UI code I need to make explicit calls to those RO list objects' static Get method, and then these RO list objects will be populated with data by DataPortal_Fetch method.

Am I right ? 

Do you have a UI code example, I just want to see how you call a child object's static method and how you can handle the Async call.

 

 

Copyright (c) Marimer LLC