Pergunta

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?

Foi útil?

Solução

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.

Outras dicas

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." );
    }
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top