Question

I am using XAF, I have a Questions Business object and Answers Business object.There are one to many relationship between these business objects.Every question must have one correct answer.If there are more than one correct answer or no correct answer,I should cancel saving.How can I satisfy this condition?

Was it helpful?

Solution

You can use the built-in XAF Validation module and the RuleCriteria attribute. If your business rule cannot be expressed via the Criteria Language syntax, then you can use the RuleFromBooleanProperty attribute and write any logic you want in code.

OTHER TIPS

public partial class Question:XPObject
{
    protected override void OnSaving()
    {
        if(this.Answers.Count == 1) base.OnSaving();
        else throw new UserFriendlyException( "You need to have one correct answer." );
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top