Some additional info:
I've been able to grab the ProbedKeyResolver from the DataSourceResolver and store it in a static property (of type OBJECT) that I then make a separate RPC call to restore it on the server after the entity cache state has finished serializing back to the client.
This obviously is not a long-term solution; it only works during the development phase (when everyone is running off their own IIS server or Cassini server) since modifying the ProbedKeyResolver would affect all BOS connections for the one single instance of the Entity Service (please correct me if that assumption is wrong). It seems like we'd need some kind of fix that would not require nulling out the ProbedKeyResolver once it's been set.
public class DataLoaderService
{
public void LoadInitialDataAsync()
{
var manager = GlobalEntityManager.Current;
ServerMethodDelegate myDelegate = new ServerMethodDelegate(LoadInitialData);
manager.InvokeServerMethodAsync(myDelegate, ServerMethodCallback, null, null);
}
private void ServerMethodCallback(InvokeServerMethodEventArgs args)
{
var manager = GlobalEntityManager.Current;
EntityCacheState cache = (EntityCacheState)args.Result;
if (cache != null)
{
cache.Merge(manager, new RestoreStrategy(true, true, MergeStrategy.OverwriteChanges));
}
// make a second RPC call to restore the key resolver
ServerMethodDelegate myRestoreDelegate = new ServerMethodDelegate(RestoreKeyResolver);
manager.InvokeServerMethodAsync(myRestoreDelegate, null, null, null);
}
public static object savedResolver { get; set;}
[AllowRpc]
public static EntityCacheState LoadInitialData(IPrincipal principal, EntityManager manager, params object[] args)
{
if (savedResolver == null)
{
// grab it so it can be restored in a subsequent call
var resolver = manager.DataSourceResolver.ProbedKeyResolver;
// cast it as an object so it doesn't get wiped out when we set the ProbedKeyResolver to NULL later
savedResolver = (object) resolver;
}
... load up the entity manager with a bunch of entities...
// wipe out the ProbedKeyResovler so the cache will serialize
manager.DataSourceResolver.ProbedKeyResolver = null;
var cache = manager.CacheStateManager.GetCacheState();
return cache;
}
[AllowRpc]
public static string RestoreKeyResolver(IPrincipal principal, EntityManager manager, params object[] args)
{
if (savedResolver != null)
{
manager.DataSourceResolver.ProbedKeyResolver = (IDataSourceKeyResolver)savedResolver;
}
return string.Empty;
}
}