【发布时间】:2010-09-23 19:07:17
【问题描述】:
我有一个非常简单的 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
【问题讨论】:
标签: c# json wcf-data-services odata