Hello,
I'm writting a small silverlight demo and I ran into an issue where
I don't know if my assumption of how to use the DataProtal is wrong.
In the Demo I have 4 objects that deal with data on the server
and 1 object that I like to deal with data locally.
The 4 object with remote data work fine.
The 1 object with local data I'm having a problem
calling the local DataPortal_Fetch method.
In the following code sample 3 of the 4 Factory Methods
work as I expected but the one that should call the
local DataPortal_Fetch calls the remote DataPortal_Fetch.
[Serializable]
public class TestObject : BusinessBase<TestObject>
{
public static PropertyInfo<String> NameProperty = RegisterProperty<String>(c => c.Name);
[Required(ErrorMessage = "User Name required")]
public String Name
{
get { return GetProperty(NameProperty); }
set { SetProperty(NameProperty, value); }
}
#if SILVERLIGHT
// OK - Calls the local DataPortal_Create.
public static void NewLocalTestObject(EventHandler<DataPortalResult<TestObject>> callback)
{
DataPortal.BeginCreate<TestObject>(callback, DataPortal.ProxyModes.LocalOnly);
}
// Err - Calls the remote DataPortal_Fetch. It should call the Local DataPortal_Fetch.
public static void GetLocalTestObject(EventHandler<DataPortalResult<TestObject>> callback)
{
DataPortal.BeginFetch<TestObject>(callback, DataPortal.ProxyModes.LocalOnly);
}
// OK - Calls the remote DataPortal_Create.
public static void NewRemoteTestObject(EventHandler<DataPortalResult<TestObject>> callback)
{
DataPortal.BeginCreate<TestObject>(callback);
}
// OK - Calls the remote DataPortal_Fetch.
public static void GetRemoteTestObject(EventHandler<DataPortalResult<TestObject>> callback)
{
DataPortal.BeginFetch<TestObject>(callback);
}
public override void DataPortal_Create(Csla.DataPortalClient.LocalProxy<TestObject>.CompletedHandler handler)
{
Name = "Local Create";
handler(this, null);
}
public void DataPortal_Fetch(Csla.DataPortalClient.LocalProxy<TestObject>.CompletedHandler handler)
{
Name = "Local Fetch";
handler(this, null);
}
#else
protected override void DataPortal_Create()
{
Name = "Remote Create";
}
private void DataPortal_Fetch ()
{
Name = "Remote Fetch";
}
#endif
}
Am I wrong to assume that we can have few objects call local DataPortal
while the rest of them call the remote DataPortal?
Thank You.
Luigi
Only BeginCreate has the overload to allow the ProxyMode parameter.
In 4.1 you need to use the long form:
var dp = new DataPortal<TestObject>();
dp.FetchCompleted += callback;
dp.BeginFetch();
Hi Rocky,
Thank you for your reply, I have changed
public static void GetLocalTestObject(EventHandler<DataPortalResult<TestObject>> callback)
{
DataPortal.BeginFetch<TestObject>(callback, DataPortal.ProxyModes.LocalOnly);
}
to
public static void GetLocalTestObject(EventHandler<DataPortalResult<TestObject>> callback)
{
var dp = new DataPortal<TestObject>();
dp.FetchCompleted += callback;
dp.BeginFetch();
}
I still get the same results as before, meaning when I Call GetLocalTestObject it still sets
the Name Property to "Remote Fetch" and not to "Local Fetch" which is what I'm try to do.
I'm looking to have the TestObject DataPortal_XYZ access the Isolated Storage in Silverlight
while all the other objects DataPortal_XYZ continue to access the data on the server.
Thank You
Luigi
Sorry, you need to pass the ProxyModes parameter to the new DataPortal<T> call.
Rocky,
It works like a charm!!!!
Many Thanks for your help
Luigi
Hello,
I have a similar problem,
I want my BeginFetch to call my remote DataPortal_Fetch. But the problem is that its not entering the Remote DataPortal_Fetch whenever the BeginFetch() is called. What have you done so it can call the Remote one? I have configured all the WCFproxy stuff and I'm using the compression folders.
I appreciate any help
Thanks
Ziad
Is the client Silverlight, WP7, WPF, or something else?
The data portal defaults to using LocalProxy in most cases. Silverlight is the only place it defaults to using WcfProxy.
Thanks for your reply.
I've found the error, it was in the Webconfig...
Thx again
Ziad
Copyright (c) Marimer LLC