0
votes

To grab some content from a WCF Data Service into my View Model is straight forward:

public const string RequestsPropertyName = "Requests";
private DataServiceCollection<Request> _requests = null;
public DataServiceCollection<Request> Requests
{
  get { return _requests; }

  set
  {
    if (_requests == value) { return; }

    var oldValue = _requests;
    _requests = value;

    RaisePropertyChanged(RequestsPropertyName, oldValue, value, true);
  }
}

and then

Requests.LoadAsync(query);

But what if I have a property which is not a collection?

public const string RequestDetailsPropertyName = "RequestDetails";
private Request _requestDetails = null;
public Request RequestDetails
{
  get { return _requestDetails; }

and so on. Where do I get the 'LoadAsync(query)' method from?

Thank you,

Ueli

1

1 Answers

0
votes

This is a pretty simple thing to do. You just need to use the DomainContext in your application. This is where you create your query from, then apply the result to your property.

Here is an example of what this might look like in your code:

    void LoadRequest(int requstID)
    {
        var query = workContext.GetRequestByIDQuery(requestID);
        workContext.Load(query, lo =>
        {
            DispatcherHelper.CheckBeginInvokeOnUI(() =>
                    {
                        if (lo.HasError)
                            throw lo.Error;
                        else
                            RequestDetails = lo.Entities.Single();
                    });
        }, null);
    }

In this example, the workContext object is the DomainContext. The query is an specific version on the server - you can also just contruct the query client side with:

.Where(r => r.RequestID == requestID)  

After the async call, it thows any errors that occurred from the async call, and then returns the only entity returned. If you get more than 1 entity, you might use .First() instead.

If this is not enough to get you going, let me know and I can explain further.