CSLA 4.1: DataPortal_Fetch nullifies my list

CSLA 4.1: DataPortal_Fetch nullifies my list

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


hramos360 posted on Wednesday, April 27, 2011

Hi,

I' m to CSLA 4, could explain why I'm having a problem with the following:

 

I derived from a NameValueList and provide a static factory "GetList(parms)" synchronous method

where I create my criteria object and pass it into the DataPortal.Fetch<T>(criteria) method.

So far so good. 

I step through the code and the DataPortal_Fetch method is invoked

where I processed to access the data I need and populate my list.

Before leaving the DataPortal_Fetch method, my list contains 11 items.

However, when returning back to my static factory method

"GetList(parms)", the list is set to null.

 

Any idea why?  I'm thinking its a configuration issue.  I have not set any configuration values yet, and I'm using the default values.

 

 

 

 

 

 

RockfordLhotka replied on Wednesday, April 27, 2011

Can you share the factory and DP_Fetch method code?

hramos360 replied on Wednesday, April 27, 2011

I've stripped off the silverlight asynch code for this posting. Thanks for the help.

 

    [Serializable]
    public class FirePropertyList : NameValueListBase<int, FireProperty>
    {
        // must have default contstructor for Silverlight support
        private FirePropertyList() { /* require use of factory methods */ }

        private static FirePropertyList _list;

        public static void InvalidateCache()
        {
            _list = null;
        }

this is my factory get:

#if !SILVERLIGHT // Silverlight can't work with synchronous calls, but we provide synchronous calls for .NET clients.
        /// <summary>
        /// Sends a request to the DataPortal to return a lookup list of Fire Property Classes.
        /// </summary>
        /// <param name="transect">The Miami 21 Transect</param>
        /// <param name="intensity">The Miami 21 Intensity</param>
        /// <returns>A name-value list of Fire Property Classes</returns>
        public static FirePropertyList GetFireProperties(string transectCode, string intensityCode)
        {
            if (_list == null)
            {
                FirePropertyListCriteria criteria = new FirePropertyListCriteria(transectCode, intensityCode);
                _list = DataPortal.Fetch<FirePropertyList>(criteria);
            }
            return _list;
        }

 

Here is my DataPortal_Fetch:

      private void DataPortal_Fetch(FirePropertyListCriteria criteria)
        {
            RaiseListChangedEvents = false;
            IsReadOnly = false;

            using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["BusinessMiami"].ConnectionString))
            {
                _list = new FirePropertyList();
                _list.IsReadOnly = false;
                foreach (DataRow row in dsPropertyCodes.Tables["PropertyCodes"].Rows)
                {

                    FireProperty propertyCode = new FireProperty((int)row["FirePropertyCode"],
                        row["Description"].ToString(),
                        "Long Description");
                    _list.Add(new NameValuePair(propertyCode.ClassCode, propertyCode));
                }
                _list.IsReadOnly = true;
            }

            RaiseListChangedEvents = true;
        }

 

 

 

RockfordLhotka replied on Wednesday, April 27, 2011

Your problem is that the DP_Fetch code is interacting with _list.

The DP_Fetch code is running in an instance of the object, and it needs to interact only with this - not the _list field.

hramos360 replied on Wednesday, April 27, 2011

Indeed. That did the trick.  Thanks again Rocky.  It's been a while since I worked with CSLA (last on 2.0).  The framework has evolved greatly!

Copyright (c) Marimer LLC