Can ReadOnlyListBase be a SwitchableObject?

Can ReadOnlyListBase be a SwitchableObject?

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


ddredstar posted on Tuesday, March 22, 2011

Can ReadOnlyListBase be a SwitchableObject?

 

JonnyBee replied on Tuesday, March 22, 2011

Do you mean: can ReadOnlyListBase be a Root object or a Child object depending on which Factory methos is used to create the object.

Yes it can - just that ReadOnlyList and ReadOnlyBase objects has no concept of being a Root or Child object (no means to mark a readonly object as Root or Child). The main purpose of root/child is to identify the root object as the only object to allow Save.

ddredstar replied on Tuesday, March 22, 2011

[Serializable]    
    public class ReviewList : ReadOnlyListBase<ReviewList,ReviewInfo>
    {
        internal static ReviewList GetReviewByClientId(int clientId)
        {
            return DataPortal.FetchChild<ReviewList>(new SingleCriteria<int> (clientId)); //error happen here
        }
#if SILVERLIGHT
        public ReviewList() {}

        public static void SearchReview(string year,int region,int status,string clientName,string reviewer, EventHandler<DataPortalResult<ReviewList>> callback)
        {
            DataPortal<ReviewList> dp = new DataPortal<ReviewList>();
            dp.FetchCompleted += callback;
            dp.BeginFetch(new SearchCriteria(year, region, status, clientName, reviewer));
        }       
        
#else
        private ReviewList()
        {}
        
        #region Data Access
        private void DataPortal_Fetch(SearchCriteria criteria)
        {
            Database db = EnterpriseLibraryContainer.Current.GetInstance<Database>();
            ReviewDAO recordDao = new ReviewDAO(db);
            this.RaiseListChangedEvents = false;
            this.IsReadOnly = false;

            using (SafeDataReader reader = new SafeDataReader(recordDao.Search(criteria.Year, criteria.Region, criteria.Status, criteria.ClientName, criteria.Reviewer)))
            {
                while (reader.Read())
                {
                    this.Add(ReviewInfo.GetRecordInfo(reader));
                }
            }

            this.RaiseListChangedEvents = true;
            this.IsReadOnly = true;
        }

        private void Child_Fetch(SingleCriteria<int> clientId)
        {
            Database db = EnterpriseLibraryContainer.Current.GetInstance<Database>();
            ReviewDAO recordDao = new ReviewDAO(db);
            this.RaiseListChangedEvents = false;
            this.IsReadOnly = false;

            using (SafeDataReader reader = new SafeDataReader(recordDao.GetByClientId(clientId.Value)))
            {
                while (reader.Read())
                {
                    //this.Add(ReviewInfo.GetRecordInfo(reader));
                    this.Add(new ReviewInfo(reader.GetString("CLIENTNAME")));
                }
            }

            this.RaiseListChangedEvents = true;
            this.IsReadOnly = true;
        }
        #endregion
#endif

 

Above is my ReadOnlyList object, when LoadProperty of this object at Parent object, an exception was thrown said " Child_Fetch not implemented" , please help me.

Copyright (c) Marimer LLC