WCF DataService update certain column
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开发者_StackOverflow社区 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?
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.
精彩评论