views:

12

answers:

1

Hi

I've a problem updating objects with the ADO.NET Data Services.

First I've create a service, which can load and store the data. Its a basic data context which implements the IUpdatable-interface.

After that, I've created a simple service-client. I just created it with the 'Add Service'-reference in Visual Studio. Basically this service seams to work. I can query for the objects and store new objects. However I cannot update objects.

This is my update-code on the client:

        var ctx =
            new TeamDataContext(new Uri("http://localhost:8637/TeamInfoService.svc"));
        var team = ctx.Teams.First();
        team.TeamName = "New Team Name";
        ctx.UpdateObject(team);

        ctx.SaveChanges();

What my main issue is, that IUpdatable.SetValue() isn't called for the object which I want to update. Only the IUpdatable.SaveChanges() is called without updating the objects on the server.

When I create a new object, the IUpdatable.SetValue is called on the server to set the property.

So what I am doing wrong? Are my expectations wrong? Is IUpdatable.SetValue supposed to be called when updating a object? Or do I need to do additional things to do updates?

Edit: I just watched the HTTP-requests between the client and the server. The client send a HTTP-Merge request with the changes. However I still don't know why the changes aren't stored.

A: 

I've just found out whats the issue and feel like an idiot right now. The TeamName-property was the Key of the object. Of course, when you change the key, it actually cannot find the object to update anymore. And therefore it cannot update the property.

So, never try to update the key of the object =)

Gamlor
It's a bit different in fact. It should still find the object (the context remembers the link to the entity regardless of the key value), but the server will ignore udpates to the key property, since that would change the identity of the entity, which is not allowed. Note that it will do so silently (by design).
Vitek Karas MSFT
Thanks for more accurate explanation
Gamlor