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
Try this:
class DashboardRootDal : Csla.Server.ObjectFactory
{
public DashboardRoot Fetch(object crit)
{
var criteria = (DashboardCriteria) crit;
…
return result;
}
}
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
The problem wasn't with the fetch, but with the criteria. The Criteria object needs a default constructor:
public DashboardCriteria() {}
Todd
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 or for async call with local portal in SL/WP with async data access to webservice: public class DashboardRootDal : Csla.Server.ObjectFactory // just semantical suger, not actual code
{
// this is the most basic method and parameters
public object Fetch(object criteria)
{
---
return result;
}
}
{
public void Fetch(object criteria, EventHandler<DataPortalResult<DashboardRoot>> callback)
{
// start async
// 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