我有一個非常簡單的WCF數據服務應用程序,我正在做一些基本的CRUD操作。對於正在更改的實體集,我有ChangeInterceptor,但ChangeInterceptor中的對象是數據庫中的當前狀態,而不是HTTP PUT中發送的內容。 有沒有辦法在保存之前驗證對象的屬性?我可以在保存更改之前驗證實體嗎?
這裏是我的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;
}
}
這裏是我的客戶端代碼(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");
}
});
這裏是JSON被髮送到服務器:
以下是收到消息時的ChangeInterceptor:
我已經上傳的代碼爲這個項目在這裏:http://andyjmay.com/test/2921612/ODataTest.zip
+1 for include source。 – jfar 2010-09-27 03:25:21