I have a very simple WCF Data Services application and I am doing some basic CRUD operations. I have a ChangeInterceptor on the entity set that is changing, but the object in the ChangeInterceptor is the current state in the database, not what is sent in the HTTP PUT. Is there a way to validate the properties of the object before saving it?
Here is my ChangeInterceptor:
[ChangeInterceptor("People")]
public void OnChangePerson(Person personChanging, UpdateOperations updateOperations) {
switch (updateOperations) {
case UpdateOperations.Change:
// personChanging is the database version here, not the changed version.
break;
default:
break;
}
}
Here is my client-side code (jQuery):
var data = {
FirstName: "NewFN",
LastName: "NewLN"
};
$.ajax({
type: "PUT",
url: serviceUrl + "/People(" + personID + ")",
contentType: "application/json",
dataType: "json",
data: JSON.stringify(data),
success: function (data) {
alert("Success!");
},
error: function (error) {
alert("An error occured");
}
});
Here is the JSON being sent to the server:
Here is the ChangeInterceptor when the message is received:
I have uploaded the code for this project here: http://andyjmay.com/test/2921612/ODataTest.zip