Hi robert.hui;
If I understand your question correctly, I believe you can accomplish what you want with IEntityServerFakeBackingStore.RestoreAsync operation.
The idea is to populate a real EntityManager's cache with some Users data and allow a fake EntityManager to import that cache to its own cache thus populating the fake EntityManager with some data.
Please see code snippets below.
public void PopulateFakeEmWithUsersBeforeLogin() {
var fakeEm = new NorthwindIBEntityManager(compositionContextName: CompositionContext.Fake.Name);
var coop = Coroutine.Start( () => PopulateWithUsersCore(fakeEm) );
coop.Completed += (s, args) => {
var isSuccessful = args.CompletedSuccessfully;
var error = args.Error;
fakeEm.Users.ExecuteAsync(op => {
var isSuccessful2 = op.CompletedSuccessfully;
var error2 = op.Error;
var list = new List<User>(op.Results);
});
};
}
private IEnumerable<INotifyCompleted> PopulateWithUsersCore(NorthwindIBEntityManager fakeEm) {
var realEm = new NorthwindIBEntityManager();
var fakeBackingStore = fakeEm.CompositionContext.GetFakeBackingStore();
//Populate realEm cache with Users
var query = realEm.Users;
var queryOp = query.ExecuteAsync();
queryOp.Completed += (s, args) => {
var isSuccessful = args.CompletedSuccessfully;
var error = args.Error;
var users = new List<User>(args.Results);
};
yield return queryOp;
//Populate fakeEm with realEM cache
var realEmCacheState = realEm.CacheStateManager.GetCacheState();
var restoreOp = fakeBackingStore.RestoreAsync(realEmCacheState);
restoreOp.Completed += (s, args) => {
var isSuccessful = args.CompletedSuccessfully;
var error = args.Error;
};
yield return restoreOp;
}
Edited by DenisK - 28-Mar-2011 at 1:55pm