Print Page | Close Window

Verifier trigger on entity subtype doesn't fire on set

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2009
Forum Discription: For .NET 3.5
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=1485
Printed Date: 17-Apr-2025 at 10:27am


Topic: Verifier trigger on entity subtype doesn't fire on set
Posted By: DanW
Subject: Verifier trigger on entity subtype doesn't fire on set
Date Posted: 21-Sep-2009 at 8:46am
We are using a lot of Entities that have child types as keys, like status fields and such, and when a verifier trigger is set to fire on the change event for these types, it doesn't.  In the example below, the Status can be several different values (and exists as a related entity to the parent entity) and two of them, disputed or no response, require a comment to be added to the record.   The trigger on the comment field fires on set reliably,  but the status change trigger only fires during the entity save, not during the property set. 
 
Here's the code:   (the DealConfStatus is a type, the ConfComment is a string).

[VerifierProvider]

public static IEnumerable<Verifier> GetVerifiers(object verifierProviderContext)

{

List<Verifier> verifiers = new List<Verifier>();

verifiers.Add(DisputeOrNoResponseStatusVerifier());

verifiers.Add(DisputeOrNoResponseCommentVerifier());

return verifiers;

}

private static Verifier DisputeOrNoResponseStatusVerifier()

{

string description = "When a confirm is marked Disputed or No Response, the Comment must be updated";

DelegateVerifier<DealConfirmation> verifier = new DelegateVerifier<DealConfirmation>(description, DisputeCommentVerifierCondition);

verifier.AddTrigger(DealConfirmation.EntityPropertyNames.DealConfStatus);

verifier.ExecutionModes = VerifierExecutionModes.All;

return verifier;

}

private static Verifier DisputeOrNoResponseCommentVerifier()

{

string description = "When a confirm is marked Disputed or No Response, the Comment must be updated";

DelegateVerifier<DealConfirmation> verifier = new DelegateVerifier<DealConfirmation>(description, DisputeCommentVerifierCondition);

verifier.AddTrigger(DealConfirmation.EntityPropertyNames.ConfComment);

verifier.ExecutionModes = VerifierExecutionModes.InstanceAndOnPostsetTriggers;

return verifier;

}

private static VerifierResult DisputeCommentVerifierCondition(DealConfirmation dealConf, TriggerContext triggerContext, VerifierContext verifierContext)

{

if (dealConf.DealConfStatus.Key == DealConfStatusEnum.Disputed || dealConf.DealConfStatus.Key == DealConfStatusEnum.NoResponse)

{

return new VerifierResult(DealConfirmation.ConfCommentEntityProperty.GetValue(dealConf, EntityVersion.Original) != DealConfirmation.ConfCommentEntityProperty.GetValue(dealConf, EntityVersion.Current) && dealConf.ConfComment != null && dealConf.ConfComment != "");

}

else

{

return new VerifierResult(true);

}

}
 
 

 




Replies:
Posted By: kimj
Date Posted: 22-Sep-2009 at 10:23am
By default the VerificationSetterOptions is set to 'None' for navigation properties.   When off, no verifiers will be called when the setter is called.  I don't really know why we have this default, but you can work around this limitation.  The entity properties are immutable after creation, but fortunately you can use a property interceptor action to modify the options on the fly.  The BeforeSet interceptor below sets the VerificationSetterOptions prior to invoking verification and the property setter.  I used AfterSet verification here, but you can use before and/or after. 

[BeforeSet(EntityPropertyNames.DealConfStatus)]
public void BeforeSetStatus(NavigationEntityPropertySetInterceptorArgs<DealConfirmation, Status> args) {
   args.VerificationSetterOptions = VerificationSetterOptions.AfterSet;
}
Once the interceptor action is in place, your custom verifier for the scalar navigation property will work.
 



Print Page | Close Window