2017-04-11 38 views
0

我一直在为我们在DevForce中的实体进行验证,并且设法让我需要的一切工作从验证导航属性开始。DevForce验证返回Ok对于尚未设置的导航属性

我已经尝试在属性上放置一个RequiredValueVerifier属性,并且确实在UI上显示验证错误,但是一旦我使用Manager.VerifierEngine.Execute({entitytovalidate}),结果就会返回OK。

我知道DevForce创建了nullos,我们可以修改属性在所述的nullos中的含义,但是我希望VeirifierEngine在没有更新nullo的值时不会返回Ok。

我目前的解决方法是在用于FKey的Id上有一个辅助Int32RangeVerifier,但我并不乐意将它作为解决方法。

试图做到这一点,而不必为这些属性创建验证程序提供程序。

如果有人有解决这个问题,我会非常感谢,如果你可以分享。

这里是当前工作周围的样本:

namespace BearPaw.Models.Main 
{ 
[MetadataType(typeof(TechnicianNoteMetadata))] 
public partial class TechnicianNote { 

    public static TechnicianNote Create(int byUserId, DateTimeZone clientZone, DateTime userUtc) 
    { 
     var newItem = new TechnicianNote() 
     { 
      CreatedById = byUserId, 
      CreatedDate = userUtc, 
      CreatedDateTz = clientZone.Id, 
      ModifiedById = byUserId, 
      ModifiedDate = userUtc, 
      ModifiedDateTz = clientZone.Id 
     }; 
     return newItem; 
    } 

} 

    public class TechnicianNoteMetadata 
    { 
    [Int32RangeVerifier(ErrorMessage = "Note Category is required", MinValue = 1)] 
    public static int NoteCategoryId; 

    [RequiredValueVerifier(DisplayName = "Note Category")] 
    public static NoteCategory NoteCategory; 

    [RequiredValueVerifier(DisplayName = "Note Detail")] 
    public static string NoteDetail; 

    } 
} 

提前感谢

回答

0

您可以创建一个自定义的验证来处理导航属性验证,并直接将其添加到VerifierEngine与如果您不想使用IVerifierProvider,则使用AddVerifier方法。

例如:如果你想,与归属核查员坚持您可以为您的验证自定义属性

var verifier = new NullEntityVerifier(typeof(TechnicianNote), "NoteCategory"); 
_em1.VerifierEngine.AddVerifier(verifier); 

public class NullEntityVerifier : PropertyValueVerifier 
{ 
    public NullEntityVerifier(
     Type entityType, 
     string propertyName, 
     string displayName = null) 
     : base(new PropertyValueVerifierArgs(entityType, propertyName, true, displayName)) { } 

    public NullEntityVerifier(PropertyValueVerifierArgs verifierArgs) 
     : base(verifierArgs) { } 

    protected override VerifierResult VerifyValue(object itemToVerify, object valueToVerify, TriggerContext triggerContext, VerifierContext verifierContext) 
    { 
     var entity = valueToVerify as Entity; 
     var msg = $"{this.ApplicableType.Name}.{this.DisplayName} is required."; 
     return new VerifierResult(entity != null && !entity.EntityAspect.IsNullEntity, msg); 
    } 
} 

为了增加引擎。有关更多信息,请参阅DevForce Resource Center

+0

非常好,我已经完全忘记了归属验证者可能是一个很好的方法来做到这一点。感谢那。 –