I’m using SL 5.0 and EntityFramework. I need to get data from two entities, but I don’t like the way which I’m doing.. through callbacks.
var context = ...
context.Load(context.GetTestTemplatesSummaryQuery("OPA-3DKCL2")).Completed += (s, e) =>
{
var result = context.GetTestTemplatesSummary_Results;
var result2 = ...
context.Load(context.GetTestTemplatesSummaryQuery(result)).Completed += (s2, e2) =>
{
...
};
};
I’m looking for an elegant way to do this.
What you’re doing is completely right for .Net versions 1.0 to 4.0. This is how asyncronous programming works in the world of .Net.
With .Net 4.5 there is a new async/await mechansim for asynchronous programming which looks like this:
When you compile the code it gets broken down into a series of asynchronous methods, but the code the developer writes is significantly simplified.
As mentioned above, if you have VS 2012 (VS 11) then you can download a pack that allows you to use await async with Silverlight 5. If you’re not using VS 2012 then what you’re doing currently is exactly right.