(Csla 4, Silverlight 5)
I'm having some trouble understanding how to accomplish calling fetch on a BLB when the call requires multiple parameters.
In .Net, I usually have a simple class with my parameters as class properties that I wrap in a SingleCriteria during the fetch:
MyCriteria c = new MyCriteria(param1, param2, param3);
MyObj bo = DataPortal.Fetch<MyObj>(new SingleCriteria<MyObj, MyCriteria>(c));
return bo;
In Silverlight, I tried the same thing:
MyCriteria c = new MyCriteria(param1, param2, param3);
DataPortal<MyObj> dp = new DataPortal<MyObj>();
dp.FetchCompleted += handler;
dp.BeginFetch(new SingleCriteria<MyObj, MyCriteria>(c));
The data portal requires that all types you pass through the data portal implement IMobileObject. The easiest way to accomplish this is to subclass one of the CSLA base types. In your case, subclass CriteriaBase.
Also, make sure to use managed backing fields so they automatically serialize. Otherwise you'll need to override the get/set state methods as described in the 'Using CSLA 4' books.
Thanks for the quick response Rocky. I had gave that a shot (I tried before without managed backers) with the same results. Am I missing something obvious?
using System;
using Csla;
using Csla.Serialization;
namespace MyNamespace
{
[Serializable]
public class MyCriteria : CriteriaBase<MyCriteria>
{
private String _param1;
public String param1
{
get { return _param1; }
set { _param1 = value; }
}
private String _param2;
public String param2
{
get { return _param2; }
set { _param2 = value; }
}
private String _param3;
public String param3
{
get { return _param3; }
set { _param3 = value; }
}
public MyCriteria () { }
}
Use managed properties.
Thanks for the response, tho apparently my understanding of what "managed backing fields" is incorrect.
My criteria class had private backing fields for the properties, tho even a class with no properties at all has the same error. Per your suggestion, I added the properties as such with the same results:
public static PropertyInfo<int?> param1Property = RegisterProperty(new PropertyInfo<int?>("param1", "param1"));
public int? param1
{
get { return ReadProperty(param1Property); }
set { LoadProperty(param1Property, value); }
}
SingleCriteria is supposed to ONLY wrap one value - not a new criteria object and should now be considered oblsolete..
So your MyCriteria object should inherit from CriteriaBase and implement managed properties and have a default (parameterless) public constructor.
Then use that object itself - do not wrap inside a SingleCriteria object.
MyCriteria c = new MyCriteria(param1, param2, param3);
DataPortal<MyObj> dp = new DataPortal<MyObj>();
dp.FetchCompleted += handler;
dp.BeginFetch(c);
That now makes perfect sense... thanks for the assist!
Copyright (c) Marimer LLC