New Posts New Posts RSS Feed: Verifier trigger on entity subtype doesn't fire on set
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Verifier trigger on entity subtype doesn't fire on set

 Post Reply Post Reply
Author
DanW View Drop Down
Newbie
Newbie
Avatar

Joined: 04-Aug-2009
Posts: 6
Post Options Post Options   Quote DanW Quote  Post ReplyReply Direct Link To This Post Topic: Verifier trigger on entity subtype doesn't fire on set
    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);

}

}
 
 

 

Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post 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.
 
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down