views:

18

answers:

1

I have the following table:

SomeName

ID number(8) not null,
Field1 varchar2(50) not null,
Field2 varchar2(50) not null,
Field3 varchar2(50) not null

In this table I have the following rows:

ID,Field1,Field2,Field3
12,'text1','text2','text3'

Now I want to update only the field2 (with an ajax request):

HTTP PUT http://host/DataService/SomeName(12M)
Accept: application/json, text/javascript, */*
Content-Type: application/json; charset=utf-8
{ Field2: 'updated field 2' }

I would have expected that this would translate to:

update sometable 
set field2 = 'updated field 2' 
where id = '12'

but it doesn't. Instead I receive an error that says that field1 and field3 can not be null. Is there an easy way around this, so that only the columns specified in the request get updated? Do I have to select the affected row first in order to complete the missing values (which I don't want for performance reasons)? I also don't want to store the not affected columns in hidden fields on the client side, just to get the update to work. I'm using the EFOracleProvider with EF4.

Any Ideas?

+1  A: 

You need to use MERGE instead of PUT. PUT semantics are "overwrite". So it first clears all the properties to their default values (default is defined by the provider). And then it applies the properties you sent in the request. MERGE semantins are "merge". It does not clear the properties, it just applies the ones you sent in the request.

Vitek Karas MSFT
Thank you very much. I didn't know that there was introduced a new http verb for doing such operations.
By the time WCF Data Services was designed there was not standard HTTP verb to do the "merge" update. So the new MERGE was used. Since than the PATCH was introduced and we are considering adding support for PATCH in the next release. But their behavior is very very similar, it's really just a different verb for the same thing.
Vitek Karas MSFT