I am having the following issue: Sometimes, when I am issuing a DomainService call using WCF RIA Services, I got the callback right but the loadoperation I have assigned has no results, meaning no entities are returned and the “IsComplete” property is false.
The following code resumes what I am doing, including the LoadOperation definition, the calling function and the callback function:
LoadOperation lo;
private void CallDomainService(){
DomainContext dc = new DomainContext();
lo = dc.Load(dc.GetDataQuery());
lo.Completed += new EventHandler(lo_Completed);
}
And it executes well and calls properly lo_completed…
void lo_Completed(object sender, EventArgs e){
}
}
The issue is that I am getting properly the details of the load Operation, but some random times, it does not return the object properly, it is not null but its .IsComplete property is False and the Entities collection is empty, though that it has had been processed properly by the server.
The trick or workaround here is to get, in this exact case, the loadoperation from the server, which is a reference to the right load operation. The code should be like this:
LoadOperation<EntityType> lo2 = (LoadOperation<EntityType>)sender;
}
And with this, problem solved.
Are you having this random issue or others? anybody found why this is happening?
Storing the LoadOperation as a class member to be used between different methods calls is not good idea because is leads to concurrency issues. Such LoadOperation barely can be called “client-side operation” – it’s just wrong concept.
On other hand, Load() method of DomainContext has an overloaded version that receives the callback address that be called upon load completion. This callback receives the right LoadOperation as argument without any “trick” or “workaround”.
LikeLike
Hi Oleg, Thanks for the information!! 🙂
It is curious that most of the examples I’ve seen are written like this… when I have to use a LoadOperation I always make sure There is no other one running, with a flag/semaphore system so they don’t collide… but you’re right, it’s not as solid as what you are proposing :).
And I agree that this is not only a Client’s work but a Load from the server, so it’s a more complex thing… maybe I haven’t explained properly..
If you could put a simple example, it would be great.
Best,
LikeLike
Here’s a simple example using one of the overload methods of the DomainContext.Load Method :
private void Query_Loaded(LoadOperation lo) {
MessageBox.Show(lo.IsComplete.ToString());
}
context.Load(context.GetEntityQuery(), Query_Loaded, null);
LikeLike