[英]how do I cancel an update for an entity in RESTier that fails custom validation logic?
I am using RESTier 0.4.0-rc2. 我正在使用RESTier 0.4.0-rc2。
With OnUpdating... if the entity fails my custom validation logic I have no way to cancel the update, and return a custom error. 使用OnUpdating ...如果实体无法通过我的自定义验证逻辑,则无法取消更新并返回自定义错误。
With CanUpdate... I can cancel the update by returning false, but there is no entity passed in to apply my custom logic to, and no way to provide a custom error. 使用CanUpdate ...,我可以通过返回false来取消更新,但是没有传递任何实体来应用我的自定义逻辑,也没有办法提供自定义错误。
Seems like a fundamental flaw, am I missing something? 似乎是一个基本缺陷,我是否缺少某些东西?
Even you already have the answer, I would like to provide it for others. 即使您已经有了答案,我也想提供给其他人。
If you want some customized logic for update validation, you can implement a class implements interface IChangeSetEntryValidator, validate in any logic you want, and then add logic like 如果您需要一些定制的逻辑来进行更新验证,则可以实现一个类,实现IChangeSetEntryValidator接口,以所需的任何逻辑进行验证,然后添加类似
DataModificationEntry dataModificationEntry = entry as DataModificationEntry;
var entity = dataModificationEntry.Entity;
// Customized validate logic and if error, add a error validation result.
validationResults.Add(new ChangeSetValidationResult()
{
Id = dataModificationEntry.EntitySetName+ dataModificationEntry.EntityKey,
Message = "Customized error",
Severity = ChangeSetValidationSeverity.Error,
Target = entity
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.