CSLA .NET

Vibrant discussion about CSLA .NET and using the framework to build great business applications.

Forum has moved

New location: CSLA .NET forum


CSLA .NET Resources:
  • CSLA .NET forum
  • CSLA .NET home page
  • BusinessRule - How to get context.Target to have the current values

    rated by 0 users
    Not Answered This post has 0 verified answers | 4 Replies | 1 Follower

    Not Ranked
    5 Posts
    Joe posted on Thu, Jun 12 2014 11:50 AM

    I am trying to create a business rule that needs the current value of two other fields in the target object.  The target object always has the previous values when the rule executes.  Is there a working example of how to implement a business rule that interacts with the business object.

    Thanks.

    Joe

    All Replies

    Top 10 Contributor
    2,279 Posts

    Hi,

    The target object is always the "current" object and the current values but it may be that the rule is executed before values have been updated by another rule?

    Can you provide us with a small sample solution?

    Jonny Bekkum, Norway CslaContrib Coordinator

    Not Ranked
    5 Posts
    Joe replied on Fri, Jun 13 2014 9:53 AM

    Thank you for getting back to me.  I figured it out. I needed to set up the Dependencies so that all of the validations would fire.  However, I do have another question.  Does the

    BusinessRules.AddRule(

     

    new Dependency(ClientIsHomeLessProperty, StateIdProperty));

    BusinessRules.AddRule(

     

    new Dependency(OutOfStateZipProperty, StateIdProperty));

    over ride the

    BusinessRules.ProcessThroughPriority = 2; ?

    My State Rule

    BusinessRules.AddRule(

     

    new RuleStateIdValid(StateIdProperty) { Priority = 0 });

    When the State Id validation fails, Id does not exist.  The

    BusinessRules.AddRule(

     

    new RuleOutOfStateZipValidStates(OutOfStateZipProperty) { Priority = 3 });

    still executes.

    Thanks.

    Joe

    Top 10 Contributor
    2,279 Posts

    Hi,

    You probably have misunderstood how the Priority property is used.

    Rules is always executed on a Per-Property basis and Priority is only ever used to set the order of execution within the same PrimaryProperty.

    Jonny Bekkum, Norway CslaContrib Coordinator

    Not Ranked
    5 Posts
    Joe replied on Fri, Jun 13 2014 2:18 PM

    Then I must have misread page 86 in the "CSLA 4: Creating Business Objects".

    Short-Circuiting Rules

    In this example I’ve changed the value to 5, so in instances of this particular business class rules at priority 5 or less will always execute, and those at priority 6 and higher will only run if no validation rule has failed.

    Thanks.

    Joe

    Page 1 of 1 (5 items) | RSS

    Copyright (c) 2006-2014 Marimer LLC. All rights reserved.
    Email admin@lhotka.net for support.
    Powered by Community Server (Non-Commercial Edition), by Telligent Systems