I use a DataProvider like so
provider.FactoryParameters.Clear();
provider.FactoryMethod =
"CreateMyBO";provider.Refresh();
Where The factory method looks like:
public
static void CreateMyBO(EventHandler<DataPortalResult<MyBO>> handler){
DataPortal<MyBO> dp = new DataPortal<MyBO>();dp.CreateCompleted += handler;
dp.BeginCreate();}
I now have a situation where I want to create a new MyBO based on the MyBO currently in the DataProvider; so something like this
provider.FactoryParameters.Clear();
MyBO exp = provider.Data as MyBO;
provider.FactoryParameters.Add(exp);
provider.FactoryMethod = "CreateMyBO";
provider.Refresh();
So I rewrite my factory method like
public static void CreateMyBO(MyBO expense, EventHandler<DataPortalResult<MyBO>> handler)
{.....
The question is what do I need to do inside this new overload to avoid a trip down the wire to the server side data portal? I'd like to create a new MyBO load the properties with the ones from the exisiting MyBO and raise the appropriate event for the DataProvider
You have the data portal configured for remote use, and you want it to be remote (normally). But in this particular case, you want to run the data portal in local mode.
If that's the scenario, then the answer is that the constructor on DataPortal<T> has an overload where you can force the object to run in local mode. This is something you do in your factory method, so the choice between local and remote is encapsulated in the factory, and is transparent to the UI.
Thanks for the pointer.
That is the scenario remote normally but local in this case.
For others I created the following methods. I think I'm restricted to the DataPortal_Create being public because of MethodCaller.FindMethod.
#if
SILVERLIGHTpublic static void CreateMyBO(MyBO myBO, EventHandler<DataPortalResult<MyBO>> handler)
{DataPortal<MyBO> dp = new DataPortal<MyBO>(DataPortal.ProxyModes.LocalOnly);
dp.CreateCompleted += handler;
dp.BeginCreate(myBO);}
public
void DataPortal_Create(Expense expense, Csla.DataPortalClient.LocalProxy<Expense>.CompletedHandler handler){//do the work here}
#endif
I spoke too soon. I thought all I had to do was make a series of LoadProperty calls in the new (local) DataPortalCreate but that left the DataProvider with IsBusy = true and no new object.
What am I missing?
Answer found at
http://www.lhotka.net/weblog/CSLALightDataPortalAndNlevelUndo.aspx
public
void DataPortal_Create(Expense expense, Csla.DataPortalClient.LocalProxy<Expense>.CompletedHandler handler){
LoadProperty<
int>(MyBOIdProperty, 0); base.MarkNew(); base.ValidationRules.CheckRules();handler(
this, null);}
Copyright (c) Marimer LLC