Criteria values don't appear to be making it from WP7 to server

Criteria values don't appear to be making it from WP7 to server

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


itogroup posted on Friday, February 24, 2012

After making sure everything inherits from a CSLA base class and has a parameterless constructor, I finally seem to have a working link from WP7 to the server! The only problem is that my DataPortal_Fetch methods aren't getting the values that are set in the criteria object. Specifically:

 

        internal static void BeginGetStaff(string username, string password, EventHandler<DataPortalResult<HarldIdentity>> callback)
        {

            StringStringCriteria criteria = new StringStringCriteria(username, password);
            DataPortal.BeginFetch<HarldIdentity>(criteria, (o, e) =>
                {
                    if (e.Error != null) throw e.Error;
                    callback(o, e);
                });
        }

        private void DataPortal_Fetch(StringStringCriteria criteria)
        {
            if (String.IsNullOrEmpty(criteria.Value1))
                throw new ArgumentNullException("username");

                [...]
        }

 

    [Serializable()]
    public class StringStringCriteria : CriteriaBase<StringStringCriteria>
    {
        public /*readonly*/ string Value1 { get; set; }
        public /*readonly*/ string Value2 { get; set; }

        public StringStringCriteria() { }
        public StringStringCriteria(string value1, string value2)
        {
            Value1 = value1;
            Value2 = value2;
        }
    }

Before calling BeginFetch, the criteria object has its values set, but the ArgumentNullException in DataPortal_Fetch keeps getting thrown and sent back to the phone.

RockfordLhotka replied on Friday, February 24, 2012

You must use managed backing fields for your properties for them to automatically serialize. In other words, standard RegisterProperty style property declarations as shown in the Using CSLA 4 books.

The data portal uses the MobileFormatter to serialize objects over the network, including the criteria object. The MobileFormatter can only serialize registered properties automatically.

Another alternative is for you to override OnGetState/OnSetState and manually insert/remove the field values from the serialization stream. This is discussed in the Using CSLA 4: Data Portal Configuration book.

itogroup replied on Friday, February 24, 2012

As always Rocky, you're a sanity saver! I'm still so used to the CSLA 2 and CSLA 3 style declarations. Looks like I really should have read the Data Portal Configuration book.

Copyright (c) Marimer LLC