Reputation: 21
I am sorry if this is a newbie question, but I am new to C# programming.
But I am trying to write a WCF data service and it reads data and spits out an odata feed just fine. I added the service reference in VS which created service types and data models for me, but I seem to be missing a SaveChanges()
method (which I see being called in a bunch of tutorials.)
This has lead me to IUpdatable
, the current stop down the rabbit hole. What does it mean when someone says "your service doesn't support updates because it doesn't implement IUpdatable
." How to I implement this interface? What does it even mean to implement this interface?
Also, this is for a Windows Phone app.
Upvotes: 0
Views: 1140
Reputation: 2831
IUpdatable is described by it's designers here: WCF Data Service Blog: IUpdatable & ADO.Net DataServices Framework
Upvotes: 0
Reputation: 13320
If the problem is not the missing SaveChanges method on the client (which Mark's answer above should solve), and you have authored a service which is supposed to support read-write access, then you might need to implement IUpdatable interface (on the server).
If your service uses EF provider, then this should already work as the EF provider implements IUpdatable out of the box.
If your service uses reflection provider, then you will need to implement IUpdatable over your context. There's some description here: http://msdn.microsoft.com/en-us/library/dd723653.aspx.
If you are using a custom provider, then you will also need to implement the IUpdatable and there are samples of that as well, but I don't think you are going this route :-)
Upvotes: 1
Reputation: 4336
Since Windows Phone 7 is Silverlight based and therefore required to be async, there is no SaveChanges
method on the context but rather a BeginSaveChanges
and EndSaveChanges
method pair. You can call them like so:
private void SaveChanges_Click(object sender, RoutedEventArgs e)
{
// Start the saving changes operation.
svcContext.BeginSaveChanges(SaveChangesOptions.Batch,
OnChangesSaved, svcContext);
}
private void OnChangesSaved(IAsyncResult result)
{
// Use the Dispatcher to ensure that the
// asynchronous call returns in the correct thread.
Dispatcher.BeginInvoke(() =>
{
svcContext = result.AsyncState as NorthwindEntities;
try
{
// Complete the save changes operation and display the response.
WriteOperationResponse(svcContext.EndSaveChanges(result));
}
catch (DataServiceRequestException ex)
{
// Display the error from the response.
WriteOperationResponse(ex.Response);
}
catch (InvalidOperationException ex)
{
messageTextBlock.Text = ex.Message;
}
finally
{
// Set the order in the grid.
ordersGrid.SelectedItem = currentOrder;
}
}
);
}
That sample is from http://msdn.microsoft.com/en-us/library/gg521146(VS.92).aspx.
Upvotes: 1