Passing a Criteria object into a data portal return incorrect parameter passed

Passing a Criteria object into a data portal return incorrect parameter passed

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


thaehn posted on Wednesday, September 28, 2011

I am trying to pass a criteria object into the fetch method using a factory:

    [Serializable]

    public class DashboardCriteria : CriteriaBase<DashboardCriteria>

    {

        public static readonly PropertyInfo<int> UserIdProperty = RegisterProperty<int>(c => c.UserId);

        public int UserId

        {

            get { return ReadProperty(UserIdProperty); }

            set { LoadProperty(UserIdProperty, value); }

        }

        

 

        public DashboardCriteria(int id, bool sysUse, string group)

        {

            UserId = id;

            SysUse = sysUse;

            Group = group;

        }

    }

 

But I am getting an error that the parameters are incorrect.  Here is the call:

        public static void GetDashboardRoot(int userId, bool sysUse, string group, EventHandler<DataPortalResult<DashboardRoot>> callback)

        {

            DashboardCriteria criteria = new DashboardCriteria(userId, sysUse, group);

            DataPortal.BeginFetch<DashboardRoot>(criteria, callback);

        }

 

 

And here is the data portal:

    class DashboardRootDal : Csla.Server.ObjectFactory

    {

        public DashboardRoot Fetch(DashboardCriteria criteria)

        {

           

 

            return result;

        }

 

    }

 

 

Any idea on what I need to do?

Todd

JonnyBee replied on Wednesday, September 28, 2011

Try this:

    class DashboardRootDal : Csla.Server.ObjectFactory

    {

        public DashboardRoot Fetch(object crit)

        {

            var criteria = (DashboardCriteria) crit;

           

 

            return result;

        }

 

    }

 

 

thaehn replied on Thursday, September 29, 2011

I had alredy tried that. It didn't work either.  I has worked when I just passed in the the normal SingleCriteria:

 DataPortal.BeginFetch<DashboardRoot>(new SingleCriteria<DashboardRoot, int>(userId), callback);

But nothing else has worked.

Todd 

thaehn replied on Thursday, September 29, 2011

The problem wasn't with the fetch, but with the criteria. The Criteria object needs a default constructor:

 public DashboardCriteria() {}

Todd

JonnyBee replied on Thursday, September 29, 2011

Hi,

What is you client platform? Silverlight?
Which version of Csla?

If it is Silverlight then make sure you have:

So - one of these should work: 

    public class DashboardRootDal : Csla.Server.ObjectFactory
 
   {
        // this is the most basic method and parameters
        public object Fetch(object criteria)
        {
           ---
           return result;
        }
    }

 or for async call with local portal in SL/WP with async data access to webservice:

    public class DashboardRootDal : Csla.Server.ObjectFactory
 
   {
        public void Fetch(object criteria, EventHandler<DataPortalResult<DashboardRoot>> callback)
        {
  
         // start async 
           

           // just semantical suger, not actual code
           // make sure to always call the callback in async callback from no matter if successs or fail
              if (e.Error != null) 
                callback.Invoke(ex, null);
              else

                callback.Invoke(null, result);
  
      }
    }

 

 

Copyright (c) Marimer LLC