Skip to content

Instantly share code, notes, and snippets.

@Phanatic
Created August 21, 2009 03:07
Show Gist options
  • Select an option

  • Save Phanatic/171620 to your computer and use it in GitHub Desktop.

Select an option

Save Phanatic/171620 to your computer and use it in GitHub Desktop.
/// <summary>
/// Executes the URI and loads the DataServiceCollection with the results of the request
/// </summary>
/// <typeparam name="TEntity">The entity type for the DataServiceCollection</typeparam>
/// <param name="context">The DataServiceContext instance that will be used
to query the DataService</param>
/// <param name="collection">The DataServiceCollection<paramref name="TEntity"/>
which will be loaded the the results of this query</param>
/// <param name="requestUri">The URI to query for data from the DataService</param>
public static void LoadDataServiceCollection<TEntity>(this DataServiceContext context,
DataServiceCollection<TEntity> collection,
Uri requestUri) {
context.BeginExecute<TEntity>(requestUri,
(asResult) =>{
Application.Current.RootVisual.Dispatcher.BeginInvoke(() => {
try {
var dsCollection = asResult.AsyncState as DataServiceCollection<TEntity>;
var queryResponse = context.EndExecute<TEntity>(asResult)
as QueryOperationResponse<TEntity>;
dsCollection.Add(resultEntity);
}
else {
dsCollection.Load(queryResponse);
}
}
catch (Exception) {
throw;
}
finally {
}
}
);
}, collection);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment